Jump to content


Photo

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


  • Please log in to reply
2 replies to this topic

#1 thehigherentity

thehigherentity
  • Members
  • PipPipPip
  • Advanced Member
  • 49 posts

Posted 21 May 2006 - 09:01 AM

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
$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
Is there a way to write this into one pass ? so SIZE= would be treated the same as size= ?
The best way to learn
is to ask you lot........

#2 thehigherentity

thehigherentity
  • Members
  • PipPipPip
  • Advanced Member
  • 49 posts

Posted 21 May 2006 - 09:35 AM

just sorted it on another forum, if any one is interested it just needed an i after the search like the following
$text = preg_replace("/\[size=(\W?)(.*?)(\W?)\](.*?)\[\/size\]/i", 
'<span style="font-size:$2px">$4</span>', $text); // lowercase

The best way to learn
is to ask you lot........

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 21 May 2006 - 11:44 AM

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 s operator too becuase your [ size][/size] tags might span 2 or more lines otherwise the PCRE engine wont include any newline characters.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users