You are here: Re: html source « PHP Language « IT news, forums, messages
Re: html source

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация