|
Post by moneyman18 on Nov 8, 2010 19:34:09 GMT
I am trying to replace UBBC in a message using preg_replace and I am not sure why it is not working correctly.
I would like to replace both [sup]Text Here[/sup] and [superscript]Text Here[/superscript] with <sup></sup>. Here is the regex.
/\[sup(erscript)?\](.*?)\[\/sup\1\]/s /\[sup(erscript)?\](.*?)\[\/sup\\1\]/s
It will replace [superscript]Text Here[/superscript], but it doesn't seem to want to replace [sup]Text Here[/sup].
Something as simple as this I can't see any reason to not work correctly.
|
|
russellr
Elite Level 1
[M:5000]
rCs?
Posts: 525
|
Post by russellr on Nov 8, 2010 20:14:18 GMT
function SupSwitch ($string) { $search = array( '@\[(?i)superscript\](.*?)\[/(?i)superscript\]@si', '@\[(?i)sup\](.*?)\[/(?i)sup\]@si' ); $replace = array( '<sup>\\1</sup>', '<sup>\\1</sup>' ); return preg_replace($search , $replace, $string); }
Help at all?
|
|
|
Post by moneyman18 on Nov 8, 2010 21:13:10 GMT
Well I was trying to do it with just one regex pattern. I will use 2 if I have to but I still would like to know what I did wrong or if it is just not possible. - Figured out how to do it.
What does (?i) do? I can't say I have seen anything like that before.
Edit: Fixed typo.
|
|