phpminify

Using PHP to minify JavaScript, HTML, and CSS WITHIN A STRING


All of the PHP minify functions I've seen have dealt with physical JavaScript, HTML, CSS files. I would like a function that, when given something like this:

$code = "<html>
    <body>";

Will minify it to one line. I am not looking for something like the YUI Compressor, as that deals with files on a server. I would simply like a function that minifies a string passed to it. Does this exist anywhere?


Solution

  • You may be looking for:

    $code = "<html>
        <body>";
    
    echo str_replace(array("\r", "\n"), '', $code);