|
-
Dec 5th, 2005, 09:38 AM
#1
Thread Starter
Hyperactive Member
creating a word filter
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.
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Dec 5th, 2005, 02:13 PM
#2
Junior Member
Re: creating a word filter
Code:
$newphrase = str_replace($old, $new, $text);
For example, If you wanted to replace all commas with spaces...
Code:
$text = "Hey,this,is,an,example";
$text = str_replace(",", " ", $text);
//$text would equal "Hey this is an example"
I hope this is what you needed
Bear
-
Dec 5th, 2005, 03:46 PM
#3
Thread Starter
Hyperactive Member
Re: creating a word filter
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...
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Dec 5th, 2005, 05:15 PM
#4
PowerPoster
Re: creating a word filter
-
Dec 5th, 2005, 05:38 PM
#5
Thread Starter
Hyperactive Member
Re: creating a word filter
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.
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Dec 5th, 2005, 06:10 PM
#6
PowerPoster
Re: creating a word filter
Crikey, how can that not exist in PHP 4?
PHP 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);
Just a modified example from PHP.net, http://au2.php.net/preg_replace
This is the other way that I've found (haven't searched hard though, so perhaps someone has a better way? )
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.
-
Dec 6th, 2005, 06:48 AM
#7
Thread Starter
Hyperactive Member
Re: creating a word filter
koo. Thanks.
Ill try it out.
EDIT - Worked out exactly how i wanted it to.
Last edited by PlaGuE; Dec 6th, 2005 at 01:41 PM.
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Dec 6th, 2005, 08:11 AM
#8
Addicted Member
Re: creating a word filter
==============================
= 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
-
Dec 6th, 2005, 08:01 PM
#9
PowerPoster
Re: creating a word filter
But str_replace is case sensitive, which isn't what hes after.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|