我需要用php中的preg_replace()替換所有塊註釋。 例如:使用preg_replace代替php中的註釋
/**asdfasdf
fasdfasdf*/
echo "hello World\n";
對於這一點:
echo "hello World\n";
我試圖從這個站點的一些解決方案,但沒有人對我的作品。 我的代碼:
$file = file_get_contents($fileinput);
$file = preg_replace('/\/\*([^\\n]*[\\n]?)*\*\//', '', $file);
echo $file;
我例如輸出是與輸入相同。 Link to my regex test
可能重複[?如何使用PHP來刪除JS評論(http://stackoverflow.com/questions/19509863/how-to-remove-js-comments-using -php) –
我知道但它對我來說不正確。例如,如果我有回聲「/ * asdfasdf * /」它將刪除它並輸出將像回聲「」 –
http://www.php.net/ manual/en/function.php-strip-whitespace.php –