thank you nico_swd i try this code but never give any output. any idea why ? <?php $text = file_get_contents("http://www.google.com/"); if (preg_match('~<body[^>]*>(.*?)</body>~si', $text, $body)){ echo $body[1]; } ?>
Because Google will redirect you, and file_get_contents() doesn't follow redirects. Try another domain and it'll work.
$ch = curl_init('http://nicoswd.com/'); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $text = curl_exec(); if (preg_match('~<body[^>]*>(.*?)</body>~si', $text, $body)) { echo $body[1]; } PHP:
i can't belive it the same resault with curl too when i read the output of curl or file get contents i get the out put but when i use preg_match i get nothing
try this.. this will work... this is written by Bony Yousuf.. original post is here.. http://www.sitepoint.com/forums/showthread.php?t=643722
remove carriage returns $str = preg_replace("/\r/", $html, "\s"); retrieve html between body tags preg_match("/<\s*body.*>.*/", $str, $body); $result = preg_split("/<(.|\n)*?>/", $body); I tried steps here, http://www.pagecolumn.com/tool/pregtest.htm
use the html dom, you can then get content of any part in the html document. http://simplehtmldom.sourceforge.net/
Make sure the actual site has a body tag. <?php $site = file_get_contents("http://en.wikipedia.org/wiki/Benchmark"); preg_match("/<body[^>]*>(.*?)<\/body>/is", $site, $matches); highlight_string($matches[1]); ?> PHP: Another example.... <?php $site = file_get_contents("http://www.google.com/codesearch"); preg_match("/<body[^>]*>(.*?)<\/body>/is", $site, $matches); highlight_string($matches[1]); ?> PHP: