相关疑难解决方法(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万
查看次数

标签 统计

comments ×1

php ×1

strip ×1