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);
?>
私の問題;
- this1 行に問題があります。
- //コメントは機能していますが、/* コメント */ を削除するコードを作成できないか、そのコメントに改行を追加できません
最近の出力は次のとおりです。
this1
this2
this3
this4
this5 http://removecomment.com
id = id.replace(/\