Page 1 of 1

Regex and case sensitivity

Posted: Tue Jun 03, 2003 2:51 pm
by ILoveJackDaniels
I'm putting together a website into which I am incorporating a form of BBCode. I want to use str_replace() to replace the BBCode with the appropriate HTML (or whatever) whenever the page is displayed, as apparently str_replace is quite fast (at least compared to ereg_replace).

However, str_replace is case sensitive. I want people to be able to use caps or lower case as they wish within the BBCode. Is there any way around this? Is there a way to make str_replace case sensitive? If not, I'm happy enough using preg_replace, but apparently that's canse sensitive too. Am I stuck with eregi_replace?

Posted: Tue Jun 03, 2003 3:01 pm
by volka
maybe you're waiting for http://php.net/str_ireplace ;)
(sorry, no real answer :oops: )

Posted: Tue Jun 03, 2003 3:06 pm
by ILoveJackDaniels
I saw that, yes, and am waiting anxiously for a few things in PHP5, but for now, am pretty stuck...

Posted: Tue Jun 03, 2003 3:07 pm
by ILoveJackDaniels
Is the following likely to work at any reasonable speed?

Code: Select all

$haystack=str_replace($needle, $replacement, strtolower($haystack));

Posted: Tue Jun 03, 2003 5:25 pm
by McGruff
preg_match can be used insensitively (iU or something).

Or just echo a string - my preferred method: :wink:

Code: Select all

<?php
echo 'BB tags must be lower case.';
?>