Case Insenitive string replacing - php 4

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
phpCCore Brad
Forum Commoner
Posts: 47
Joined: Sun Dec 04, 2005 5:46 pm
Location: Michigan, USA
Contact:

Case Insenitive string replacing - php 4

Post by phpCCore Brad »

Okay, this is a pretty basic question. What is everyone's opinion on doing case insentive string replacements in php 4. I use to user eregi_replace(), but this has started to cause problems with patterns being inputted, etc. I would love to use str_ireplace(), but since it's php 5 only I can't.

This is an example of what I mean:

Code: Select all

$find = "<title>";
$replaceWith = "<title>Yeah";
$search = "<TITLE>";

$end = eregi_replace($find, $replaceWith, $search); //works
$end = str_replace($find,$replaceWidth,$search); //Doesn't work
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

There's a link on str_ireplace() to a PHP 4 compatible version via PEAR, last I saw.

I think there was a Code Snippet posted too.

If you want to create it yourself, there's some cleverness that can be done with strtolower(), strpos(), substr() and str_replace() in a loop. ... :)
phpCCore Brad
Forum Commoner
Posts: 47
Joined: Sun Dec 04, 2005 5:46 pm
Location: Michigan, USA
Contact:

Post by phpCCore Brad »

Yeah I thought about that. I was trying to keep away from it because of how many functions I have to call etc. Trying to keep down on the load time. Was just trying to see if someone has a better way of doing it.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

There's a possibility to reduce the number of functions needed to strtolower(), strpos() and substr_replace().
phpCCore Brad
Forum Commoner
Posts: 47
Joined: Sun Dec 04, 2005 5:46 pm
Location: Michigan, USA
Contact:

Post by phpCCore Brad »

I was more of hoping of a way to force eregi to look at string as a string and not the possibilty of a pattern.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

If you seriously want to use regex, use preg_replace() and preg_quote().
Post Reply