note 53896 added to function.highlight-string
| From: | zero at osu1 dot php dot net | Date: | Thu, 16 Jun 2005 10:55:00 +0000 |
| Subject: | note 53896 added to function.highlight-string | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-90527@lists.php.net to get a copy of this message | ||
In some cases, I found that it's useful to have highlight_string format
<code>...</code> inline as part of a paragraph, and other times, as a block for
demonstrating multiple lines of code. I made this function to help out.
<?php
function highlight_code($code, $inline=false, $return=false) // Pre php 4 support for capturing
highlight
{
(string) $highlight = "";
if ( version_compare(phpversion(), "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($data, true);
}
## The classes below need to correspond to a stylesheet!
if ( $inline === true )
$highlight=str_ireplace("<code>","<code
class=\"inline\">",$highlight);
else
$highlight=str_ireplace("<code>","<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+53896
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+53896&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+53896&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+53896&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+53896&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+53896&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+53896&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+53896&report=yes
Search -- http://master.php.net/manage/user-notes.php