在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";
}
?>