I am trying to read in the body of a specific web page to display on a separate web page, but I have a little problem with it. Right now, I'm using the following code
<?php
@$doc = new DOMDocument();
@$doc->loadHTMLFile('http://foo.com');
@$tags = $doc->getElementsByTagName('body');
foreach ($tags as $tag) {
$index_text .= $tag->nodeValue;
print nl2br($tag->nodeValue).'<br />';
}
?>
This code works, however, it seems to remove a lot of formatting, which is important to me, for example, line breaks. How to stop this from happening
source
share