How to remove JS comments using PHP?

前端 未结 7 1355
慢半拍i
慢半拍i 2020-12-09 12:02

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.r

7条回答
  •  爱一瞬间的悲伤
    2020-12-09 12:26

    Try this:

    $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 //
    HTTP+'//www.googleadservices.com/pagead/conversion'
    ";
    
    $pattern = '/(?:(?:\/\*(?:[^*]|(?:\*+[^*\/]))*\*+\/)|(?:(?

    Result on codepad.org.

提交回复
热议问题