0
我分析網頁內容,並顯示在下面的方式在div:顯示網頁內容與換行符
$doc = new DOMDocument();
libxml_use_internal_errors(true);
$doc->loadHTMLFile($url);
libxml_clear_errors();
$xpath = new DOMXPath($doc);
foreach($xpath->query("//script") as $script) {
$script->parentNode->removeChild($script);
}
$textContent = $doc->textContent; //inherited from DOMNode
$text=escapeshellarg($textContent);
$test = preg_replace("/[^a-zA-Z]+/", " ", html_entity_decode($text));
但是,這也將刪除換行符(段)到$測試。 如何在上面包含換行符以便每個段落都可見?
謝謝,但它跳過換行符。這裏是我的代碼審查請http://codetidy.com/6796/ – user123