note 24543 added to function.show-source
| From: | derek at nospam dot mapiq dot com | Date: | Wed, 21 Aug 2002 02:06:40 +0000 |
| Subject: | note 24543 added to function.show-source | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-35286@lists.php.net to get a copy of this message | ||
Heres a cleaner way of doing it.
This puts less process checking on the php code, I also added it so that the lines do not wrap
around.
Enjoy.
<?php
if ( !empty ( $_REQUEST['noline'] ) ) { $noline = true; }
ob_start(); /* Turn on output buffering for capture */
show_source ( 'filename.php' ); /* output source of file */
$raw_source = ob_get_contents(); /* Get contents of buffer */
ob_end_clean(); /* Clean and end buffering */
/* We remove the <code> tags from the $raw_source for reposition */
$raw_source = ereg_replace ( "<code>", "", $raw_source );
$raw_source = ereg_replace ( "</code>", "", $raw_source );
$raw_source = explode ( '<br />', $raw_source ); /* Split the source into lines
*/
$ml = strlen ( count ( $raw_source ) ); /* find the largest length of the line number */
/**
* Check if the user requested no lines to be displayed, then
* Loop through each line and append the required information
**/
if ( !isset ( $noline ) ) /* Default of lines to be displayed */
{
for ( $i = 0; $i < count ( $raw_source ); $i++ )
{
/* Find out the gap for the number */
$gap = ( $ml - strlen ( $i ) );
/* output the line number and its contents */
$raw_source[$i] = "<FONT COLOR=#999999>[" . str_repeat(" ",
$gap ) . $i . "]</FONT>" . $raw_source[$i] . " <BR />";
}
}
else /* No lines requested */
{
for ( $i = 0; $i < count ( $raw_source ); $i++ )
{
/* output the standard line */
$raw_source[$i] = "$raw_source[$i] <BR />";
}
}
/* Convert the $raw_source back to a string format */
$raw_source = implode ( '', $raw_source );
/* Output the new $raw_source to the user */
echo "<HTML>
<BODY>
<DIV NOWRAP NOBR>
<CODE>
$raw_source
</CODE>
</DIV>
</BODY>
</HTML>";
?>
--
http://www.php.net/manual/en/function.show-source.php
http://master.php.net/manage/user-notes.php?action=edit+24543
http://master.php.net/manage/user-notes.php?action=delete+24543
http://master.php.net/manage/user-notes.php?action=reject+24543