Return to Snippet

Revision: 60424
at November 13, 2012 20:41 by krike


Updated Code
/**
* Function to minify any given string (usefull for javascript)
* @return string
* */
public function minifyJs($code)
{
    $code = preg_replace('/((?<!\/)\/\*[\s\S]*?\*\/|(?<!\:)\/\/(.*))/','',$code);
    $code = preg_replace("/\n|\r|\t/","", $code);
    return $code;
}

Revision: 60423
at November 7, 2012 20:10 by krike


Initial Code
/**
* Function to minify any given string (usefull for javascript)
* @return string
* */
public function minifyCode($code)
{
    $code = preg_replace('/((?<!\/)\/\*[\s\S]*?\*\/|(?<!\:)\/\/(.*))/','',$code);
    $code = preg_replace("/\n|\r|\t/","", $code);
    $code = preg_replace("/[ \t]{2,} /"," ", $code);
    return $code;
}

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

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

Feedback / suggestions / improvements are welcome.

Initial Title
Minify code function

Initial Tags
php, code

Initial Language
PHP