PHP----实现压缩HTML

时间:2022-01-13 10:43:02

很多时候,我们在做优化处理的时候,会考虑压缩HTML,去掉HTML里面的空格和换行。

具体实现:

public function change(){
echo "change";
$url = "http://sanqi.e0yu.com/";
$file = file_get_contents($url);
$file = preg_replace("/\t/","",$file);//将空格 替换为空
$file = preg_replace("/\r\n/","",$file);// 将换行 替换为空
echo $file;
}