I cant seem to make it so that when it searches for a word... it doesnt care about the 'caSe'.
I looked on PHP.net cuz i remembed seeing sumtin about it in an example. but....
Oh and google wasnt my friend when i searched for it.
Printable View
I cant seem to make it so that when it searches for a word... it doesnt care about the 'caSe'.
I looked on PHP.net cuz i remembed seeing sumtin about it in an example. but....
Oh and google wasnt my friend when i searched for it.
For example, If you wanted to replace all commas with spaces...Code:$newphrase = str_replace($old, $new, $text);
I hope this is what you neededCode:$text = "Hey,this,is,an,example";
$text = str_replace(",", " ", $text);
//$text would equal "Hey this is an example"
Bear
thanks for the reply. But thats not what i meant.
Im sorry for "implying my question" in a "vague" way. I do that sumtimes.
If you read my first line carefully you'll understand my question.
If Not Read on.
I cant seem to make it "not Care" about CaSe.
As in. If theres a word like Homo.(Example). It doesnt matter what the case of the word is. it will still be replaced.
Example:
Homo
HoMo
HOMO
hOmO
hOMO
etc...etc.. etc...
how bout for those whos host dont use PHP 5?
lol
cuz str_ireplace(); doesnt even "change color" in the editor.
nor does it work when run.
Crikey, how can that not exist in PHP 4?
Just a modified example from PHP.net, http://au2.php.net/preg_replacePHP Code:$string = 'The quick brown fox jumped over the lazy dog.';
$patterns[0] = '/(?i)Quick/';
$patterns[1] = '/(?i)Brown/';
$patterns[2] = '/fox/';
$replacements[2] = 'bear';
$replacements[1] = 'black';
$replacements[0] = 'slow';
echo preg_replace($patterns, $replacements, $string);
This is the other way that I've found (haven't searched hard though, so perhaps someone has a better way? :p)
The patterns are the things your searching for, replacements, whats to replace it with, and the (?i) makes it case insensitive, so it needs to be included.
koo. Thanks.
Ill try it out.
EDIT - Worked out exactly how i wanted it to.
==============================
= str_replace
==============================
Compability :
==========
works with PHP3, PHP4 and PHP5
Linux and Widnows
Code :
======
<?php
// Provides: You should eat pizza, beer, and ice cream every day
$phrase = "You should eat fruits, vegetables, and fiber every day.";
$healthy = array("fruits", "vegetables", "fiber");
$yummy = array("pizza", "beer", "ice cream");
$newphrase = str_replace($healthy, $yummy, $phrase);
?>
Descriptions :
==========
It replaces word like as given in code above.
http://ca3.php.net/manual/en/function.str-replace.php
But str_replace is case sensitive, which isn't what hes after.