note 40751 added to function.show-source
| From: | sysop at NOSPAM dot accessdeniedbbs dot net | Date: | Sat, 13 Mar 2004 00:25:20 +0000 |
| Subject: | note 40751 added to function.show-source | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-66760@lists.php.net to get a copy of this message | ||
<?php
/*
Function to show source of file with padded line numbers.
Presented in a formatted layout with ability to enable/disable
word wrapping. If file does not exist, the user is informed.
Usage: void ShowSource(string filename [, boolean|string wordwrap])
Example output:
Source File: HelloWorld.php (3 lines)
00001 <?php
00002 print "Hello World!";
00003 ?>
*/
// Example of calling the function to show the source
// for HelloWorld.php with word wrap disabled...
ShowSource("HelloWorld.php",true);
/* The function... */
function ShowSource ($filename="",$wrap=true) {
if (file_exists($filename)) {
ob_start();
show_source( $filename );
$t = ob_get_contents();
ob_end_clean();
$source=explode("<br />",$t);
$counter=1;
if ($wrap==false)
$wrap=" nowrap='nowrap'";
else $wrap="";
print "Source File: $filename (".count($source)." lines)<br /><br
/>";
print "<table cellspacing='2' cellpadding='0'>";
foreach ($source as $line) {
print "<tr><td
bgcolor='silver'>".sprintf("%05d",$counter++)."</td>";
print "<td$wrap>$line</td></tr>\n";
}
print "</table>";
}
else
print "Sorry, $filename was not located on this server...<br />";
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.show-source.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+40751
Delete -- http://master.php.net/manage/user-notes.php?action=delete+40751&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+40751&report=yes
Search -- http://master.php.net/manage/user-notes.php