Web Content: Reading Other Web Page


Web Content Tips - Part 6: You can read web page or source code of web page over HTTP. It is easy, because PHP have file functions can all be used to read remote files, file_get_contents(). All text from remote file will be stored at a variabel. Sample like this:
<?php
$url = "http://localhost:8048/blog/index.php";

$data = file_get_contents($url) or die("Cannot open URL");

echo $data;

?>

Or you want to force browser download:

<?php
$url = "http://localhost:8048/blog/index.php";

header("Content-Type: plain/text");
$data = file_get_contents($url) or die("Cannot open URL");

echo $data;

?>



Bookmark and Share Tag: web content, web page, file Category: PHP Basic Post : April 28th 2008 Read: 4,241

advertisements


blog comments powered by Disqus