Jump to content


Photo

*SOLVED* C++ highlighting


  • Please log in to reply
1 reply to this topic

#1 Brandon Jaeger

Brandon Jaeger
  • Members
  • PipPipPip
  • Advanced Member
  • 155 posts
  • LocationPA
  • Age:25

Posted 30 April 2006 - 06:02 AM

How would I highlight a string of C++ code including syntax highlighting?

Edit: Ok, so I've found GESHI now I need some help.

How would I highlight what's between the [pawn][/pawn] tags with this?
geshi_highlight($string , "cpp" , "" , false);

Edit #2: I sort of got it but the backslashes still appear. Here's my code:
    function pawn_highlight($string)
    {
        $string = str_replace("]\n", "]", $string);
        $match = array('#\[pawn\](.*?)\[\/pawn\]#se');
        $replace = array("'<div>'.geshi_highlight('$1' , 'cpp' , '' , false).'</div>'");
        $string = stripslashes($string);
        return preg_replace($match, $replace, $string);
    }

Thanks in advance.
PHP is my friend (=

#2 Brandon Jaeger

Brandon Jaeger
  • Members
  • PipPipPip
  • Advanced Member
  • 155 posts
  • LocationPA
  • Age:25

Posted 30 April 2006 - 07:30 AM

Nevermind, I believe I've solved it myself:
    function pawn_highlight($string)
    {
        $string = str_replace("]\n", "]", $string);

        $match = array('#\[pawn\](.*?)\[\/pawn\]#se');
        $replace = array("'<div>'.geshi_highlight(stripslashes('$1') , 'cpp' , '' , true).'</div>'");

        return preg_replace($match, $replace, stripslashes(stripslashes($string)));
        // I used stripslashes twice
    }
Edit: If anyone wants to see a live example of it, go here: [a href=\"http://ghw-amxx.com/pawn_hl.php\" target=\"_blank\"]http://ghw-amxx.com/pawn_hl.php[/a]
PHP is my friend (=




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users