以下是我的代碼:刪除類和H1的造型與simple_html_dom導致
$html = $_GET['html'];
$dom = file_get_html($html);
$h1 = $dom->find('h1');
echo $h1[0];
它返回H1文本,但其最初與相關的類一起。像:
<h1 class="postpageheading">the returned text </h1>
我只想要文本,甚至沒有標籤。
我該怎麼做? 謝謝。
以下是我的代碼:刪除類和H1的造型與simple_html_dom導致
$html = $_GET['html'];
$dom = file_get_html($html);
$h1 = $dom->find('h1');
echo $h1[0];
它返回H1文本,但其最初與相關的類一起。像:
<h1 class="postpageheading">the returned text </h1>
我只想要文本,甚至沒有標籤。
我該怎麼做? 謝謝。
嘗試:
echo $h1[0]->plaintext;
從你file_get_html
方法,它看起來像您使用的PHP簡單的HTML DOM解析器。
如果你在他們的快速啓動看看這裏:
http://simplehtmldom.sourceforge.net/
單擊該選項卡上的「提取從HTML內容」,並展示瞭如何使用這個plaintext
獲得內容,無需標記。
,你可以在你的結果一樣運行正則表達式:
$result = preg_replace("/[^A-Z]+/", "", $string);
或
strip_tags
如下所述:http://php.net/strip_tags
謝謝@ noa-dev。我想到這一點,但想知道是否有simplehtmldom內的東西..謝謝。 – user2742581 2015-03-13 19:48:52
謝謝各位高手爲你的快速回復。我無法接受答案,因爲我必須等待9分鐘,我會這樣做。感謝您教育我並提供資源。你搖滾! – user2742581 2015-03-13 19:10:27