Jump to content

*SOLVED* preg_replace and case sensitivity!!!!!!!!


Recommended Posts

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= ?
Link to comment
https://forums.phpfreaks.com/topic/10111-solved-preg_replace-and-case-sensitivity/
Share on other sites

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]
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.

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.