lonewolf217 Posted October 14, 2008 Share Posted October 14, 2008 I have this bit of code that i have pieced together for a BBCode translation, but it is not liking what I am using for the color but I cannot figure out why. the error I get is this Warning: preg_replace() [function.preg-replace]: Unknown modifier 'c' in \viewKB.php on line 62 where line62 is the preg_replace line function bbcode_format ($str) { $codeLayout = '<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td class="codebody">$1</td> </tr> </table>'; $simple_search = array( '/\[b\](.*?)\[\/b\]/is', '/\[i\](.*?)\[\/i\]/is', '/\[u\](.*?)\[\/u\]/is', '/\[code\](.*?)\[\/code\]/is', '/\[color=(.*?)\](.*?)\[/color\]/is' ); $simple_replace = array( '<b>$1</b>', '<i>$1</i>', '<u>$1</u>', $codeLayout, '<font color=$1>$2</font>' ); // Do simple BBCode's $str = preg_replace($simple_search, $simple_replace, $str); return $str; } Quote Link to comment https://forums.phpfreaks.com/topic/128401-solved-simple-array-preg_replace-question/ Share on other sites More sharing options...
wildteen88 Posted October 14, 2008 Share Posted October 14, 2008 As you start/end your patterns with a forward slash you must escape all forward slashes within your pattern. The pattern for your color bb code should be '/\(.*?)\[\/color\]/is' Quote Link to comment https://forums.phpfreaks.com/topic/128401-solved-simple-array-preg_replace-question/#findComment-665279 Share on other sites More sharing options...
lonewolf217 Posted October 14, 2008 Author Share Posted October 14, 2008 thanks, regex still confuses the hell out of me so i dont notice these things Quote Link to comment https://forums.phpfreaks.com/topic/128401-solved-simple-array-preg_replace-question/#findComment-665286 Share on other sites More sharing options...
wildteen88 Posted October 14, 2008 Share Posted October 14, 2008 I was in the same boat as you when I was learning regular expressions. Quote Link to comment https://forums.phpfreaks.com/topic/128401-solved-simple-array-preg_replace-question/#findComment-665287 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.