Welcome Guest, Not a member yet? Register   Sign In
highlight_code(); is not working correctly
#1

[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:
&lt;?php echo 'Hello, world!'; ?&gt
:
Code:
<code><span style="color: #000000"><span style="color: #0000BB">&lt;?php echo 'Hello, world!'; ?&gt;&nbsp;</span></code>

When I write
Code:
highlight_code("&lt;?php echo 'Hello, World!'; ?&gt;")
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.
#2

[eluser]InsiteFX[/eluser]
Maybe your calling it wrong!
Code:
$string = highlight_code($string);

InsiteFX
#3

[eluser]Unknown[/eluser]
I'm not silly. I call function correctly. Function just returns one-coloured string (blue).
#4

[eluser]Kikito[/eluser]
Do you found solution ?
#5

[eluser]InsiteFX[/eluser]
Not sure if this could be the problem, but edit your php.ini file I just found this in mine.
Code:
; Colors for Syntax Highlighting mode.  Anything that's acceptable in
; <span style="color: ???????"> would work.
; http://php.net/syntax-highlighting
;highlight.string  = #DD0000
;highlight.comment = #FF9900
;highlight.keyword = #007700
;highlight.bg      = #FFFFFF
;highlight.default = #0000BB
;highlight.html    = #000000
Remove th ; before the codes.

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB