Jump to content

*SOLVED* C++ highlighting


Brandon Jaeger

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.
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.