note 62362 added to function.highlight-file

From: Date: Sun, 26 Feb 2006 09:18:17 +0000
Subject: note 62362 added to function.highlight-file
Groups: php.notes 
Request: Send a blank email to php-notes+get-104454@lists.php.net to get a copy of this message
I use this (simple and dirty) function in my tutorials to add linenumbers. I let all the linenumbers in one table cell so it is easier for people to copy and paste the code (so they don't have to remove all the linenumbers): <?php function highlight_with_linenum($file) { //open handle, set vars $handle = fopen($file, "r"); $count = 1; $lines = ""; //look line ends while ($thisone = fread($handle, "1")) { if ($thisone == "\n") { //add number $lines .= $count . "<br />"; $count++; } } //close handle fclose($handle); //highlight contents $contents = highlight_file($file, TRUE); //print output (you could as well return now) print '<table><tr><td><code>' . $lines . '</code></td><td>' . $contents . '</td></tr></table>'; } ?> Maybe it's of use to someone ---- Server IP: 83.137.20.120 Probable Submitter: 83.116.4.239 ---- X-Spam-Status: No, hits=3.3 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER, HTML_MESSAGE autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.highlight-file.php Edit -- http://master.php.net/note/edit/62362 Del: integrated -- http://master.php.net/note/delete/62362/integrated Del: useless -- http://master.php.net/note/delete/62362/useless Del: bad code -- http://master.php.net/note/delete/62362/bad+code Del: spam -- http://master.php.net/note/delete/62362/spam Del: non-english -- http://master.php.net/note/delete/62362/non-english Del: in docs -- http://master.php.net/note/delete/62362/in+docs Del: other reasons-- http://master.php.net/note/delete/62362 Reject -- http://master.php.net/note/reject/62362 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#104454) next »