-1

Possible Duplicate:
How do I get the HTML code of a web page in PHP?

Is there a PHP code to get the HTML code of a webpage? $html = file_get_contents('https://stackoverflow.com/questions/ask'); this doesnt work. It simply loads the webpage. I want to display the HTML code when I run the code.

Thanks in advance.

Community
  • 1
  • 1
user1190937
  • 59
  • 2
  • 8

5 Answers5

1

Try:

echo htmlentities(file_get_contents('http://stackoverflow.com/questions/ask'));
benesch
  • 5,121
  • 1
  • 21
  • 35
  • Thanks a lot. This code works with the given url. But it doesnt work with 'http://www.maduraonline.com/?find=home'. It simply displays the webpage. Any idea why that is?.I want the html code of this webpage as I'm developing a translator. What can I do to get its html code? Thanks a lot – user1190937 Feb 06 '12 at 09:15
0

Perhaps try:

$html = htmlspecialchars(file_get_contents('http://stackoverflow.com/questions/ask'));

and try using the tags to output it.

kapa
  • 75,446
  • 20
  • 155
  • 173
Rick Kuipers
  • 6,498
  • 2
  • 16
  • 36
0

Just HTML encode your output, so that & becomes &, using the htmlentities function.

Adam Mihalcin
  • 13,704
  • 3
  • 31
  • 51
-1
$handle = @fopen("'http://www.webmasterworld.com", "rt");
$code = fread($handle,9000);

This is copied form another thread, but it should be good enough. It will get the code in $handle and then $code would contain 9000 bytes of that code.

tinyhook
  • 342
  • 3
  • 12
-2

Try using exec and wget together:

<?php

exec('wget http://stackoverflow.com/questions/ask -O', $array);

echo implode('<br />', $array);

?>
furtive
  • 1,569
  • 2
  • 12
  • 15