Posted By

krike on 11/07/12


php code minify

Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


Minify code function

 / Published in: PHP


A usefull function to minify code or string. This is part of the WPelements library class available on Github.

Feedback / suggestions / improvements are welcome.

  1. /**
  2. * Function to minify any given string (usefull for javascript)
  3. * @return string
  4. * */
  5. public function minifyJs($code)
  6. {
  7. $code = preg_replace('/((?<!\/)\/\*[\s\S]*?\*\/|(?<!\:)\/\/(.*))/','',$code);
  8. $code = preg_replace("/\n|\r|\t/","", $code);
  9. return $code;
  10. }

Report this snippet  


RSS Icon Subscribe to comments
Posted By: JonyGreen on December 7, 2015

i find a free online javascript minifier service to compress your js code, so it will reduce the size of web page.

You need to login to post a comment.