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
https://forums.phpfreaks.com/topic/233515-highlight-style-in-code-tag/
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.

Archived

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

×
×
  • 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.