Jump to content

Print code with line number on web page


everisk

Recommended Posts

Hello all,

 

I need some help printing some code on the page. Originally I read HTML code from a url and I need to replace 'Beginning of Line' and 'End of Line' with line number.  However, I do not know how this can be done. Any help would be really appreciated.

 

$enews = file_get_contents("http://my.sony.co.th/newsletter/issue/issue-MySony061aug22/index_en.html");
$enews = htmlspecialchars($enews);

print "<pre>$enews</pre>"

Link to comment
https://forums.phpfreaks.com/topic/69930-print-code-with-line-number-on-web-page/
Share on other sites

Try this:

<?PHP
$enews = file_get_contents("http://my.sony.co.th/newsletter/issue/issue-MySony061aug22/index_en.html");
$enews = htmlspecialchars($enews);
$enews_array = explode(chr(13),$enews);

$line_num = 1;

foreach($enews_array as $line){
echo $line_num . "" . $line;
$line_num++;
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.