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
This is my best result, following the first post and searching many sites, this function well works for javascript and css and html content in php
function _compress($html){
//remove comments
$html = preg_replace('|(?:(?:\/\*(?:[^*]|(?:\*+[^*\/]))*\*+\/)|(?:(?<!\:)\/\/.*))|', '', $html ); //Yancharuk's code/regex
// remove tabs, spaces, newlines, etc.
$html = str_replace(array(PHP_EOL, "\t"), '', $html);
//remove all spaces
$html = preg_replace('|\s\s+|', ' ', $html);
return $html;
}