-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
  • 69
  • 2
  • 8

5 Answers5

1

Try:

echo htmlentities(file_get_contents('http://stackoverflow.com/questions/ask'));
benesch
  • 5,239
  • 1
  • 22
  • 36
  • 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
  • 77,694
  • 21
  • 158
  • 175
Rick Kuipers
  • 6,616
  • 2
  • 17
  • 37
0

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

Adam Mihalcin
  • 14,242
  • 4
  • 36
  • 52
-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
  • 15
-2

Try using exec and wget together:

<?php

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

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

?>
furtive
  • 1,669
  • 2
  • 13
  • 15