php如何获取htmlcontent而不是textcontent

时间:2017-01-12 19:13:40

标签: php domdocument domxpath

var2中,我想要HTML内容,因为有一些br所以它们没有被包含在内,我希望它们被包含在内。

<?php
$url = "http://sms.hindijokes.co";
$html = file_get_contents($url);
$doc = new DOMDocument;
$doc->strictErrorChecking = false;
$doc->recover = true;
@$doc->loadHTML("<html><body>".$html."
</body>      </html>");
$xpath = new DOMXPath($doc);
$query1 = "//h2[@class='entry-title']/a";
$query2 = "//div[@class='entry-content'][1]/p";
$entries1 = $xpath->query($query1);
$entries2 = $xpath->query($query2);
$var1 = $entries1->item(0)->textContent;
$var2 = $entries2->item(0)->textContent;
echo "$var1"; 
echo "<br>";
$f = $entries2->length;
for($i = 0; $i < $f; $i++){
    echo $entries2->item($i)->textContent."\n";
}
?>

0 个答案:

没有答案