问题
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?
回答1:
You may be looking for:
$code = "<html>
<body>";
echo str_replace(array("\r", "\n"), '', $code);
回答2:
I never tried these ones, but I came across them once:
For JavaScript and CSS:
http://castlesblog.com/2010/august/14/php-javascript-css-minification
来源:https://stackoverflow.com/questions/17575992/using-php-to-minify-javascript-html-and-css-within-a-string