|
Posted by Dennis Kehrig on 02/15/07 12:41
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
Navigation:
[Reply to this message]
|