Page 1 of 1

Case Insenitive string replacing - php 4

Posted: Tue Aug 15, 2006 11:32 am
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

Posted: Tue Aug 15, 2006 11:36 am
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. ... :)

Posted: Tue Aug 15, 2006 12:20 pm
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.

Posted: Tue Aug 15, 2006 12:23 pm
by feyd
There's a possibility to reduce the number of functions needed to strtolower(), strpos() and substr_replace().

Posted: Tue Aug 15, 2006 12:38 pm
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.

Posted: Tue Aug 15, 2006 12:39 pm
by feyd
If you seriously want to use regex, use preg_replace() and preg_quote().