Thread: html source
View Single Post

  #2 (permalink)  
Old 02-15-2007
Dennis Kehrig
 
Posts: n/a
Default Re: html source

yoko wrote:
> Is there anyway to capture the html source code of a page and only grab
> the content in the body tags without using fsockopen?
> for example lets say the URL is
> $url="http://ca3.php.net/manual/en/faq.obtaining.php";
>
> Thanks to everyone that helps.


Try this (allow_url_fopen needs to be enabled, probably a bad idea):

// Get the HTML file
$html = file_get_contents($url);
// Reduce it to the contents of the <body> tag
$body = preg_replace("#^.*<body[^>]*>(.*)</body>.*$#si", "\\1", $html);
// Strip of whitespace at the beginning and the end
$body = trim($body);

Best regards,

Dennis Kehrig
Reply With Quote