gaza165 Posted October 27, 2008 Share Posted October 27, 2008 I am currently using BBCodes to do the code tag in my blog, I need a regular expression to search for php code and to change their colors acccordingly. Just like PHP Freaks does.... variables are a color functions are a colour. Just like below, thats what i want to accomplish... <?php $string = str_replace($string,"Hello","Hello there..." echo $string ?> Quote Link to comment https://forums.phpfreaks.com/topic/130257-regexx-or-bbcodes/ Share on other sites More sharing options...
gaza165 Posted October 27, 2008 Author Share Posted October 27, 2008 Can somone please help me!!!! I need a way to search for PHP code in my blog posts and to match the colors to fit with the code. Just like phpfreaks does, hope someone can help me with this. Have been tearing my hair out over this. Thanks Garry Quote Link to comment https://forums.phpfreaks.com/topic/130257-regexx-or-bbcodes/#findComment-675504 Share on other sites More sharing options...
The Little Guy Posted October 27, 2008 Share Posted October 27, 2008 Is this what you are after? http://phpsnips.com/snippet.php?id=41 Quote Link to comment https://forums.phpfreaks.com/topic/130257-regexx-or-bbcodes/#findComment-675554 Share on other sites More sharing options...
discomatt Posted October 27, 2008 Share Posted October 27, 2008 I'd do something like this: <?php $code = <<<CODE some content goes here <?php morePHPcode(); while ( !($succeed = try()) ); echo 'foo'.\$bar; ?> here's some <b>more</b> content, ect. ect. CODE; echo hiliteCode( $code ); function hiliteCode( $input ) { $regex = '/<\?.*?\?>/s'; return preg_replace_callback( $regex, create_function( '$m', 'return "<pre>".highlight_string( $m[0], TRUE )."</pre>";' ), $input ); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/130257-regexx-or-bbcodes/#findComment-675603 Share on other sites More sharing options...
DarkWater Posted October 27, 2008 Share Posted October 27, 2008 @discomatt: You don't need to use a regex for this, highlight_string() should only parse PHP stuff on its own. Quote Link to comment https://forums.phpfreaks.com/topic/130257-regexx-or-bbcodes/#findComment-676042 Share on other sites More sharing options...
discomatt Posted October 27, 2008 Share Posted October 27, 2008 Ah, should've tested it. Quote Link to comment https://forums.phpfreaks.com/topic/130257-regexx-or-bbcodes/#findComment-676089 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.