case insensitive string search and replace
Posted: Tue Feb 22, 2005 10:02 am
My next problem. I need to be able to take one string (user input) and see if another string exists within the uer input. If that string is found, I want to remove it. But I also don;t want the search to be case-sensitive. The user input needs to be able to have upper and lower case chars in it and retain its case. So switching it all to lower case isn't an option.
For example, I want to take the user string:
So that will NOT remove the "You are so", it will only remove the case matching "you are so". Anyone know how to do this? I've been looking through the manual of string functions on php.net and no luck.
Thanks,
Paul
For example, I want to take the user string:
and find and remove any of the following with the case not being a factor:You are so dumb that I .......
So after I run the user's sentence through it will strip out the "You are so" part and just give meyou are so
you're so
your so
I did get this partially working, but it only matches items of the same exact case:dumb that I ......
Code: Select all
while ($row = mysql_fetch_array($result))
$needlesї] = $rowї'phrase'];
foreach ($needles as $needle)
{
// echo "<BR>Searching "$data" for "$needle".";
$data = str_replace( ($needle." "), "", $data);
}Thanks,
Paul