在一个STRING内使用PHP最小化JavaScript,HTML和CSS [英] Using PHP to minify JavaScript, HTML, and CSS WITHIN A STRING

查看:45
本文介绍了在一个STRING内使用PHP最小化JavaScript,HTML和CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我所见过的所有PHP minify函数都处理了物理JavaScript,HTML,CSS文件.我想要一个这样的函数:

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>";

将其缩小到一行.我不需要的是 YUI压缩器,因为它可以处理服务器.我只想要一个最小化传递给它的字符串的函数.这在任何地方存在吗?

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?

推荐答案

您可能正在寻找:

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

echo str_replace(array("\r", "\n"), '', $code);

这篇关于在一个STRING内使用PHP最小化JavaScript,HTML和CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆