我有問題刪除該標籤<!-- comment -->
看起來太空標籤中的空白。如何去除它,也將其更改爲空字符不是空間的使用preg_replace()
如何從html中刪除匹配註釋標籤preg_replace
解決
只是用這個語法:
$content = "hello <!--- comment --> world";
$html = preg_replace('/<!-- comment -->/i','',$content);
輸出
hello world
我有問題刪除該標籤<!-- comment -->
看起來太空標籤中的空白。如何去除它,也將其更改爲空字符不是空間的使用preg_replace()
如何從html中刪除匹配註釋標籤preg_replace
解決
只是用這個語法:
$content = "hello <!--- comment --> world";
$html = preg_replace('/<!-- comment -->/i','',$content);
輸出
hello world
不使用的preg_replace(),你可以簡單地做:
$html = str_replace("<!-- pagebreak -->", "<!--pagebreak-->", $html);
如果評論有所不同,該怎麼辦? –
感謝哥們。目前我需要使用'preg_replace()'方法。 – abadi
是很危險的使用的preg_replace或任何其他文本的工具來操作HTML!到目前爲止的答案是可怕的,並可能導致HTML以多種方式破解。將DOM用於HTML,DOMDocument可以loadHTML(),然後您可以簡單地刪除註釋節點,或者以「pagebreak」開始的那些註釋。
謝謝,可怕像什麼?你能否就此解釋一下。謝謝 – abadi
他們打破了法律HTML,像'''
text <! - old:<! - comment - > important
''' –
到目前爲止你有什麼? –