everisk Posted September 19, 2007 Share Posted September 19, 2007 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 More sharing options...
EKINdesigns Posted September 19, 2007 Share Posted September 19, 2007 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++; } ?> Link to comment https://forums.phpfreaks.com/topic/69930-print-code-with-line-number-on-web-page/#findComment-351246 Share on other sites More sharing options...
everisk Posted September 20, 2007 Author Share Posted September 20, 2007 Thanks EKINdesigns. It worked, except that i have to change chr(13) to chr(10). But thanks a lot! Link to comment https://forums.phpfreaks.com/topic/69930-print-code-with-line-number-on-web-page/#findComment-351587 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.