[eluser]Unknown[/eluser]
At first, hi, developers.
At second, I have a problem with highlight_code() func. in my parse_bbcode() func.
Here is the code:
Code:
function parse_bbcode($str = '', $max_images = 0)
{
// Max image size eh? Better shrink that pic!
if($max_images > 0):
$str_max = "style=\"max-width:".$max_images."px; width: [removed]this.width > ".$max_images." ? ".$max_images.": true);\"";
endif;
$CI =& get_instance();
$CI->load->helper('text');
$find = array(
"'\[b\](.*?)\[/b\]'is",
"'\[i\](.*?)\[/i\]'is",
"'\[s\](.*?)\[/s\]'is",
"'\[quote\](.*?)\[/quote\]'is",
"'\[php\](.*?)\[/php\]'is",
"'\[img\](.*?)\[/img\]'i"
);
$replace = array(
'<strong>\\1</strong>',
'<em>\\1</em>',
'<s>\\1</s>',
'<span class="quote">\\1</span>',
highlight_code("\\1"),
'<img src="\\1" alt="" />'
);
return preg_replace($find, $replace, $str);
}
Function returns the following string when it's argument is
Quote:PHP Code:
<?php echo 'Hello, world!'; ?>
:
Code:
<code><span style="color: #000000"><span style="color: #0000BB"><?php echo 'Hello, world!'; ?> </span></code>
When I write
Code:
highlight_code("<?php echo 'Hello, World!'; ?>")
in my "view" file everything is OK, func. returns coloured string.
So, I'd like to hear a solution to this problem. Thank you all.
P.S. parse_bbcode() argument is from MySQL database.