note 54015 added to function.highlight-string
| From: | zer0 at osu1 dot php dot net | Date: | Tue, 21 Jun 2005 04:18:58 +0000 |
| Subject: | note 54015 added to function.highlight-string | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-90718@lists.php.net to get a copy of this message | ||
Concerning my code below:
I'm sorry, I completely forgot about str_ireplace being for PHP 5 for some reason. Also, there
was another error I missed (too many late nights ;)). Here's the corrected code:
<?php
function highlight_code($code, $inline=false, $return=false) // Pre php 4 support for capturing
highlight
{
(string) $highlight = "";
if ( version_compare(PHP_VERSION, "4.2.0", "<") === 1 )
{
ob_start(); // start output buffering to capture contents of highlight
highlight_string($code);
$highlight = ob_get_contents(); // capture output
ob_end_clean(); // clear buffer cleanly
}
else
{
$highlight=highlight_string($code, true);
}
# Using preg_replace will allow PHP 4 in on the fun
if ( $inline === true )
$highlight=preg_replace("/<code>/i","<code
class=\"inline\">",$highlight);
else
$highlight=preg_replace("/<code>/i","<code
class=\"block\">",$highlight);
if ( $return === true )
{
return $highlight;
}
else
{
echo $highlight;
}
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.highlight-string.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+54015
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54015&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54015&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54015&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54015&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54015&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54015&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+54015&report=yes
Search -- http://master.php.net/manage/user-notes.php