note 31583 added to function.highlight-string
| From: | webmaster at freetimeprojects dot com | Date: | Sat, 26 Apr 2003 22:58:19 +0000 |
| Subject: | note 31583 added to function.highlight-string | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-47156@lists.php.net to get a copy of this message | ||
This is my way to highlight a string...
If you got a big string with some pieces of php-code in it, it leaves all your text as it is made up
with your stylesheets or whatever except for the php code. So it doesn't put your normal text
between those <code></code> tags.
NOTE: you'll have to put your php-code between [php][/php] tags if you want to use this
function.
function phpHighlight($input)
{
$text = spliti("\[php\]|\[\/php\]",$input);
for($i = 0; $i < count($text); $i++) {
if(ereg("(<\?php)(.*)(\?>)",$text[$i])) {
ob_start();
highlight_string($text[$i]);
$text[$i] = ob_get_contents();
ob_end_clean();
}
else {
$text[$i] = nl2br(htmlspecialchars($text[$i]));
}
}
$text = implode("",$text);
return $text;
}
Hope this saves someone some work... ;-)
Robert.
--
http://www.php.net/manual/en/function.highlight-string.php
http://master.php.net/manage/user-notes.php?action=edit+31583
http://master.php.net/manage/user-notes.php?action=delete+31583
http://master.php.net/manage/user-notes.php?action=reject+31583