thehigherentity Posted May 21, 2006 Share Posted May 21, 2006 I'm having truble getting my head round the preg_replace, Im working on a bbcode function but cant work out if there is a way to turn the case sensative on and off, eg this is what i have at the mo[code]$text = preg_replace("/\[size=(\W?)(.*?)(\W?)\](.*?)\[\/size\]/", '<span style="font-size:$2px">$4</span>', $text); // lowercase$text = preg_replace("/\[SIZE=(\W?)(.*?)(\W?)\](.*?)\[\/SIZE\]/", '<span style="font-size:$2px">$4</span>', $text); // uppercase[/code]Is there a way to write this into one pass ? so SIZE= would be treated the same as size= ? Quote Link to comment https://forums.phpfreaks.com/topic/10111-solved-preg_replace-and-case-sensitivity/ Share on other sites More sharing options...
thehigherentity Posted May 21, 2006 Author Share Posted May 21, 2006 just sorted it on another forum, if any one is interested it just needed an i after the search like the following[code] $text = preg_replace("/\[size=(\W?)(.*?)(\W?)\](.*?)\[\/size\]/i", '<span style="font-size:$2px">$4</span>', $text); // lowercase[/code] Quote Link to comment https://forums.phpfreaks.com/topic/10111-solved-preg_replace-and-case-sensitivity/#findComment-37636 Share on other sites More sharing options...
wildteen88 Posted May 21, 2006 Share Posted May 21, 2006 Yes the i is a pattern modifier. You might want to read up on [a href=\"http://uk.php.net/manual/en/reference.pcre.pattern.modifiers.php\" target=\"_blank\"]Pattern Modifiers here[/a] also one operator you might want to use is the [b]s[/b] operator too becuase your [ size][/size] tags might span 2 or more lines otherwise the PCRE engine wont include any newline characters. Quote Link to comment https://forums.phpfreaks.com/topic/10111-solved-preg_replace-and-case-sensitivity/#findComment-37662 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.