note 27668 modified in function.highlight-file by nicos

From: Date: Sun, 15 Dec 2002 10:58:05 +0000
Subject: note 27668 modified in function.highlight-file by nicos
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-40929@lists.php.net to get a copy of this message
this script is the ULTIMATE for highlighting with line numbers: <? $contents = highlight_file($filename, true); $contents = explode('<br />', $contents); print '<html><head><style>body,code,font,td{font-family:Fixedsys,"Courier New", Courier;margin:0px}'; print '.ln{margin:0px;padding:0px;padding-right:2px; color:#ffffff;background-color:#666666;width:45px}'; print '</style></head><body>'; print '<table border=0 cellpadding=0 cellspacing=0><tr><td class=ln align=right valign=top nowrap>'; for($i=1; $i<=sizeof($contents); $i++) print "$i<br>"; print '</td><td style="cursor:normal">&nbsp;</td><td nowrap>'; foreach($contents as $line) print "$line<br>"; print '</td></tr></table></body></html>'; ?> And then for making a file highlight itself, you could include this code: <? $contents = highlight_file(basename($_SERVER['PHP_SELF']), true); // _ignore_ $contents = explode('<br />', $contents); // _ignore_ print '<html><head><style>body,code,font,td{font-family:Fixedsys,"Courier New", Courier;margin:0px} '; // _ignore_ print '.ln{margin:0px;padding:0px;padding-right:2px; color:#ffffff;background-color:#666666;width:45px}'; // _ignore_ print '</style></head><body>'; // _ignore_ print '<table border=0 cellpadding=0 cellspacing=0><tr><td class=ln align=right valign=top nowrap>'; // _ignore_ $ln=1; // _ignore_ foreach($contents as $line) if(!strstr($line, '// _ignore_')) { print "$ln<br>"; $ln++; } // _ignore_ print '</td><td style="cursor:normal">&nbsp;</td><td nowrap>'; // _ignore_ foreach($contents as $line) if(!strstr($line, '// _ignore_')) print "$line<br>"; // _ignore_ print '</td></tr></table></body></html>'; exit; // _ignore_ ?> --was-- Sorry to post so many times, but this script is the ULTIMATE for highlighting with line numbers: <? $contents = highlight_file($filename, true); $contents = explode('<br />', $contents); print '<html><head><style>body,code,font,td{font-family:Fixedsys,"Courier New", Courier;margin:0px}'; print '.ln{margin:0px;padding:0px;padding-right:2px; color:#ffffff;background-color:#666666;width:45px}'; print '</style></head><body>'; print '<table border=0 cellpadding=0 cellspacing=0><tr><td class=ln align=right valign=top nowrap>'; for($i=1; $i<=sizeof($contents); $i++) print "$i<br>"; print '</td><td style="cursor:normal">&nbsp;</td><td nowrap>'; foreach($contents as $line) print "$line<br>"; print '</td></tr></table></body></html>'; ?> And then for making a file highlight itself, you could include this code: <? $contents = highlight_file(basename($_SERVER['PHP_SELF']), true); // _ignore_ $contents = explode('<br />', $contents); // _ignore_ print '<html><head><style>body,code,font,td{font-family:Fixedsys,"Courier New", Courier;margin:0px} '; // _ignore_ print '.ln{margin:0px;padding:0px;padding-right:2px; color:#ffffff;background-color:#666666;width:45px}'; // _ignore_ print '</style></head><body>'; // _ignore_ print '<table border=0 cellpadding=0 cellspacing=0><tr><td class=ln align=right valign=top nowrap>'; // _ignore_ $ln=1; // _ignore_ foreach($contents as $line) if(!strstr($line, '// _ignore_')) { print "$ln<br>"; $ln++; } // _ignore_ print '</td><td style="cursor:normal">&nbsp;</td><td nowrap>'; // _ignore_ foreach($contents as $line) if(!strstr($line, '// _ignore_')) print "$line<br>"; // _ignore_ print '</td></tr></table></body></html>'; exit; // _ignore_ ?> http://www.php.net/manual/en/function.highlight-file.php

« previous php.notes (#40929) next »