Minify code function


/ Published in: PHP
Save to your folder(s)

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

Feedback / suggestions / improvements are welcome.


Copy this code and paste it in your HTML
  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. }

URL: https://github.com/krike/WPelements

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.