How to remove JS comments using PHP?
This question is updated: Nov. 4 2013 and answered by: Alexander Yancharuk
But there is a problem right now. A new code: id = id.replace(///g,'');
This is my example:
<?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);
?>
My Problems;
- Something wrong with the this1 line;
- The //comments is working but I can't create a codes to remove /*
comment */ or by that comment with a line break
Here is the output, recent:
this1
this2
this3
this4
this5 http://removecomment.com
id = id.replace(/
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…