Regex and case sensitivity

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
ILoveJackDaniels
Forum Commoner
Posts: 43
Joined: Mon May 20, 2002 8:18 am
Location: Brighton, UK

Regex and case sensitivity

Post 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?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

maybe you're waiting for http://php.net/str_ireplace ;)
(sorry, no real answer :oops: )
User avatar
ILoveJackDaniels
Forum Commoner
Posts: 43
Joined: Mon May 20, 2002 8:18 am
Location: Brighton, UK

Post by ILoveJackDaniels »

I saw that, yes, and am waiting anxiously for a few things in PHP5, but for now, am pretty stuck...
User avatar
ILoveJackDaniels
Forum Commoner
Posts: 43
Joined: Mon May 20, 2002 8:18 am
Location: Brighton, UK

Post by ILoveJackDaniels »

Is the following likely to work at any reasonable speed?

Code: Select all

$haystack=str_replace($needle, $replacement, strtolower($haystack));
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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.';
?>
Post Reply