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

有些话、适合烂在心里 提交于 2019-12-22 08:25:05

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!