Posted By

o0110o on 10/26/12


Tagged

php display code source


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

Some0ne
o0110o
Johnb21


Display the source code of a webpage.


 / Published in: PHP
 

URL: http://perishablepress.com/code-snippets/#code-snippets_php

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.

  1. // display source code
  2. $lines = file('http://google.com/');
  3. foreach ($lines as $line_num => $line) {
  4. // loop thru each line and prepend line numbers
  5. echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br>\n";
  6. }

Report this snippet  

You need to login to post a comment.