对于一个学校项目,我们应该压缩通过 php 生成的 html 输出。有什么办法可以做到这一点吗?例如,下面的代码不应有任何空格。先感谢您。
2 回答

慕哥6287543
TA贡献1831条经验 获得超10个赞
这就是我用的。这不是最佳的,但对我来说已经足够了:
$html = preg_replace('/(\n+|\t+|\s{2, })/misU', ' ', $html)
它删除换行符和制表符,以及 2 个或更多空格的集合。

当年话下
TA贡献1890条经验 获得超9个赞
你的代码不清楚。但是,据我了解,您正在寻求此解决方案。您想要从文本中删除空格。
$var = "Hello World!"; //var with spaces
$removespacefromvar = preg_replace('/\s+/', '', $var); //This code gonna remove the white space from $var
?>
<div><?= $removespacefromvar ?></div>
<?php
//This will output the final text where we have removed space
该<?=
图标是一个简短的 php 标签。
- 2 回答
- 0 关注
- 102 浏览
添加回答
举报
0/150
提交
取消