Click here to Skip to main content
15,173,299 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi , I need to display html source code of a url , how can i get it .

I need raw html code like this :
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1"><title>

</title></head>
<body>


I used it :
PHP
<?php  $data = file_get_contents("http://www.lorempixel.com/",0);
echo $data;
?>


But It was not getting Source code ,

Any help is appreciated !
Posted
Updated 29-Nov-14 0:17am
v3
Comments
Zoltán Zörgő 29-Nov-14 7:16am
   
What have you got than?
Srinivas08 29-Nov-14 8:37am
   
simply all that html page itself was duplicated in my webpage

PHP
$data = file_get_contents('http://www.lorempixel.com/');
echo htmlspecialchars($data);
   
Try this:
PHP
<?php  $data = file_get_contents("http://www.lorempixel.com/");
$html_encoded = htmlentities($data);
echo $html_encoded;
?>
   
v2
thanks , Now its working ... I am getting html source code as output !
   
Comments
Peter Leow 29-Nov-14 20:37pm
   
This is not a solution, should remove it. You can acknowledge the right solution by using the "Have a Question or Comment?" button. Do not forget to accept the right solutions.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900