對于一個學校項目,我們應該壓縮通過 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 關注
- 144 瀏覽
添加回答
舉報
0/150
提交
取消