Jump to content

Highlight style in code tag


fxuser

Recommended Posts

So i have a custom tag like:

[ code style=php ] [ /style]

 

The user has plenty options such as c,c++,js and more, so if the user has posted some code in php and after some code in c++ i want to search the [ code] [ /code] tags to see if the style exists , and then call the highlight function .. i suppose this can be done via regex or something similar?

 

Thanks.

Link to comment
Share on other sites

Bump*

 

Im using this for now:

$search = array(
    '/\[code style=(.*?)\](.*?)\[\/code\]/is'
);
$replace = array(
    '<div class="codetext" id="$1">$2</div>'
);
return preg_replace($search,$replace,$input);

 

so if style = php and inside the code tags i have <?php echo "test"; ?>

it will output

<div class="codetext" id="php"><?php echo "test"; ?></div>

how can i check what $1 is in order to highlight the $2 properly ?

 

thanks, please reply for any other questions.

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.