note 37045 deleted from function.highlight-file by aidan
| From: | aidan@php.net | Date: | Sun, 26 Sep 2004 13:56:55 +0000 |
| Subject: | note 37045 deleted from function.highlight-file by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-77377@lists.php.net to get a copy of this message | ||
Note Submitter: denis dot lanoire at wanadoo dot fr
----
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