什么是从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 - 这就是在谷歌上出现的东西绊倒了.