Jump to content

Archived

This topic is now archived and is closed to further replies.

Brandon Jaeger

*SOLVED* C++ highlighting

Recommended Posts

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?
[code]geshi_highlight($string , "cpp" , "" , false);[/code]

Edit #2: I sort of got it but the backslashes still appear. Here's my code:
[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);
    }[/code]

Thanks in advance.

Share this post


Link to post
Share on other sites
Nevermind, I believe I've solved it myself:
[code]    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
    }[/code]
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]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.