Roee Posted April 29, 2006 Share Posted April 29, 2006 hi all,in the last days, i have been tring to make a system with BBCODE.. i want to make the content of [mycode] and [/mycode], in color in php.i want to make it in preg_replace(there is no another way..)i write this code:[code]$content = preg_replace( "#\[mycode\](.+?)\[/mycode\]#is", "XXXXXXXXX", $content ); [/code]but i have no idea what to write in XXXXXXXXX...how i use in highlight_string ??thanks Quote Link to comment https://forums.phpfreaks.com/topic/8717-preg_replace-with-highlight_string/ Share on other sites More sharing options...
LiLaaron Posted April 30, 2006 Share Posted April 30, 2006 this may help[a href=\"http://us3.php.net/highlight_string\" target=\"_blank\"]http://us3.php.net/highlight_string[/a]Aaron Quote Link to comment https://forums.phpfreaks.com/topic/8717-preg_replace-with-highlight_string/#findComment-32100 Share on other sites More sharing options...
Roee Posted April 30, 2006 Author Share Posted April 30, 2006 this is not help.. Quote Link to comment https://forums.phpfreaks.com/topic/8717-preg_replace-with-highlight_string/#findComment-32152 Share on other sites More sharing options...
Brandon Jaeger Posted April 30, 2006 Share Posted April 30, 2006 [a href=\"http://us3.php.net/manual/en/function.highlight-string.php#49506\" target=\"_blank\"]http://us3.php.net/manual/en/function.high...tring.php#49506[/a] Quote Link to comment https://forums.phpfreaks.com/topic/8717-preg_replace-with-highlight_string/#findComment-32249 Share on other sites More sharing options...
stino Posted May 23, 2006 Share Posted May 23, 2006 and thats not working ...heres what that script outputs:''.highlight_string(stripslashes('<html>......................highlight_string is included in the [b]output[/b], so not executed so not doing what it has to do! Quote Link to comment https://forums.phpfreaks.com/topic/8717-preg_replace-with-highlight_string/#findComment-38216 Share on other sites More sharing options...
wildteen88 Posted May 23, 2006 Share Posted May 23, 2006 You'll want to use preg_replace_callback instead if you want to call a function when using regular expressions like so:[code]<?phpfunction highlight_php($matches){ $php = highlight_string($matches[0], true); //strip out the phptags $php = preg_replace("#(\[php\]|\[/php\])#i", "", $php); return $php;}$str = "[php]<?phpecho \"hello world\";?>[/php]";$match = "#\[php\](.*?)\[\/php\]#is";$php = preg_replace_callback($match, 'highlight_php', $str);echo $php;?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/8717-preg_replace-with-highlight_string/#findComment-38274 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.