相关疑难解决方法(0)

从PHP代码中自动删除注释的最佳方法

什么是从PHP文件中删除注释的最佳方法?

我想做类似strip-whitespace()的东西 - 但它也不应该删除换行符.

例如:

我要这个:

<?PHP
// something
if ($whatsit) {
    do_something(); # we do something here
    echo '<html>Some embedded HTML</html>';
}
/* another long 
comment
*/
some_more_code();
?>
Run Code Online (Sandbox Code Playgroud)

成为:

<?PHP
if ($whatsit) {
    do_something();
    echo '<html>Some embedded HTML</html>';
}
some_more_code();
?>
Run Code Online (Sandbox Code Playgroud)

(虽然如果删除注释的空行仍然存在,那就不行了).

这可能是不可能的,因为需要保留嵌入式HTML - 这就是在谷歌上出现的东西绊倒了.

php comments strip

48
推荐指数
5
解决办法
4万
查看次数

用于PHP的JSON解析器,支持注释

任何人都可以建议一个JSON解析器允许任何类型的注释,使用PHP绑定 - 需要严重的配置文件的评论,但json_decode不支持它们.

(我知道:1.其他格式如YAML,2.评论不属于标准的一部分)

更新:

我们为什么不使用:

  • YAML:基准测试显示速度较慢 - 我们可能希望通过网络发送数据 - 不确定YAML是否最适合.

  • XML:太冗长 - 简单的人工编辑是必需的.而且不需要XML的扩展功能.

  • INI:数据中存在可变深度的层次结构和嵌套.我们需要一种无处不在的格式,因为数据可能与应用程序一起分发,也可能与其他语言的应用程序一起使用.

  • 预处理:数据可以由用户提供和共享,在向应用添加数据之前很难强制要求预处理.

php json comments

10
推荐指数
2
解决办法
2458
查看次数

如何使用PHP删除JS注释?

如何使用PHP删除JS注释?这个问题已更新:2013年11月4日回答:Alexander Yancharuk但是现在有一个问题.新代码:id = id.replace(/\//g,'');

这是我的例子:

<?php
$output = "
//remove comment
this1 //remove comment
this2 /* remove comment */
this3 /* remove
comment */
this4 /* * * remove
* * * *
comment * * */
this5 http://removecomment.com
id = id.replace(/\//g,''); //do not remove the regex //
";

$output = preg_replace( "/(?:(?:\/\*(?:[^*]|(?:\*+[^*\/]))*\*+\/)|(?:(?<!\:)\/\/.*))/", "", $output ); //Yancharuk's code/regex
// "/(?<!\:)\/\/(.*)\\n/ = my oldest code

echo nl2br($output);
?>
Run Code Online (Sandbox Code Playgroud)

我的问题;

  1. 这一行有问题;
  2. //注释正在运行,但我无法创建代码来删除/*注释*/或带有换行符的注释

这是输出,最近:



this1
this2
this3
this4
this5 http://removecomment.com
ID = …

javascript php

10
推荐指数
3
解决办法
1万
查看次数

缩小Smarty中的HTML输出

如何缩小Smarty中的所有输出HTML模板?

像这样: $smarty->minify = true;

PS:我找到了{strip}功能,但是我应该在所有.tpl文件中使用此功能。我有很多.tpl文件,这种方式对我来说是不可能的。

html compression smarty minify

4
推荐指数
3
解决办法
6577
查看次数

标签 统计

php ×3

comments ×2

compression ×1

html ×1

javascript ×1

json ×1

minify ×1

smarty ×1

strip ×1