Monday, 23 February 2015

PHP: Display source code of any webpage

Want to be able to display the source code of any webpage, with line numbering? 
Here is a simple code snippet to do it. Just modify the url on line 2 at your convenience. 
Or even better, make a pretty function according to your needs.
<?php // display source code
$lines = file('http://google.com/');
foreach ($lines as $line_num => $line) { 
 // loop thru each line and prepend line numbers
 echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "
\n";
}
?>

0 comments:

Post a Comment