Case-insensitive search and replace using an array
| From: | René Fournier | Date: | Tue, 06 May 2003 16:41:10 +0000 |
| Subject: | Case-insensitive search and replace using an array | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-146539@lists.php.net to get a copy of this message | ||
$patterns = array("Mr.","Ms.","Mrs.","unknown");
$piece = str_replace($patterns,"",$piece);
This code works, but what I'd like to do is change it so that if $piece contains "Mr." or "mr.", both are caught and replaced. Preg_replace allows for case-insensitive search items, but I can't seem to combine that parameter with the $patterns search array.
Any ideas? Thanks.
...Rene
---
René Fournier,
rene@smartslitters.com
Toll-free +1.888.886.2754
Tel +1.403.291.3601
Fax +1.403.250.5228
www.smartslitters.com
SmartSlitters International
#33, 1339 - 40th Ave NE
Calgary AB T2E 8N6
Canada