php清除網(wǎng)頁中的空格方法
php by 黃業(yè)興 at 2020-04-03
今天做了個采集的功能需要去除網(wǎng)頁的空格看代碼:
public function clear_html($string){
$str = trim($string); //清除字符串兩邊的空格
$str = preg_replace("/\t/","",$str); //使用正則表達(dá)式替換內(nèi)容,如:空格,換行,并將替換為空。
$str = preg_replace("/\r\n/","",$str);
$str = preg_replace("/\r/","",$str);
$str = preg_replace("/\n/","",$str);
$str = preg_replace("/ /","",$str);
return trim($str); //返回字符串
}
去除空格之后就可以用正則匹配內(nèi)容!
請關(guān)注我們微信公眾號:mw748219