Jump to content

[SOLVED] Trying to retrive source code of a website.


Torflu

Recommended Posts

Hey,

 

I am trying to retrieve a source code,of a site,using file_get_contents.The simple code i am using is

 

<?php
ini_set('display_errors', 1);
ini_set('log_errors', 1);
ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
error_reporting(E_ALL);
$file = file_get_contents("http://xxxx.org/index.php");
echo $file;
?>

 

But in my editor,the output is the website,not the source.Can anyone please suggest me where am i wrong and what should be the right code ?

Link to comment
Share on other sites

But in my editor,the output is the website,not the source.Can anyone please suggest me where am i wrong and what should be the right code ?

 

Which is correct. You're fetching a website's source code and displaying it in a browser. Thus the page is rendered exactly as it is on the original site. Run the $file through the htmlentities function before outputting to the brower to see the source code. This will convert all special HTML characters to the equivlant codes, preventing the browser from interpreting their special meaning.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.