note 37045 added to function.highlight-file
| From: | denis dot lanoire at wanadoo dot fr | Date: | Fri, 31 Oct 2003 19:31:36 +0000 |
| Subject: | note 37045 added to function.highlight-file | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-59597@lists.php.net to get a copy of this message | ||
Here is a function to highlight a php source with the ability to hide a part of the code (for
instance, a database login name)
To start the hidden part, write a @@BEGIN_HIDE_CODE token in a comment and to finish the hidden
part, write a @@END_HIDE_CODE in a comment.
function highlight_and_hide ($source) {
$t_lines = file($source); // read the file into a string
$step = 0;
$str = "";
foreach ($t_lines as $line) {
switch ($step) {
case 0: // nothing to hide
if (stristr($line, "@@" . "begin_hide_code") ) { // found a begin hide
token
$step = 1;
$str .= "/* !!! BEGINNING OF THE HIDDEN CODE PART\n";
} else {
$str .= $line;
} // if
break;
case 1: // found a begin hide token
if (stristr($line, "@@" . "end_hide_code") ) { // found an end hide token
$step = 0;
$str .= " !!! END OF THE HIDDEN CODE PART */\n";
} else {
$str .= " ...\n";
} // if
break;
} // switch
} // for
highlight_string($str);
} // function
----
Manual Page -- http://www.php.net/manual/en/function.highlight-file.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+37045
Delete -- http://master.php.net/manage/user-notes.php?action=delete+37045&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+37045&report=yes
Search -- http://master.php.net/manage/user-notes.php