You are here: Re: [PHP] best way todo a case insensitive str_replace « PHP « IT news, forums, messages
Re: [PHP] best way todo a case insensitive str_replace

Posted by John Nichel on 02/21/05 18:04

pmpa wrote:
> Hi all.
>
> What is the best way to do a string insensitive replace?
> Currently I am doing:
>
> $replace = "g r";
> $arr = explode(" ",$replace);
> $text = "PHP is GreaT!";
> for($i=0;i<count($arr);$i++){
> $text =
> str_replace(strtolower($arr[$i]),"<b>".strtolower($arr[$i])."</b>",$text);
> $text =
> str_replace(strtoupper($arr[$i]),"<b>".strtoupper($arr[$i])."</b>",$text);
> }
>
> Works except for "Ph","PhP","gr" etc...
> I am looking for suggestions before using str_split(); because my $replace
> string can be a bit large :)

You could use a regular expression...

preg_replace ( "/needle/i", "replace", $haystack );
------------------------^

The 'i' makes it case insensitive.

--
John C. Nichel
ÜberGeek
KegWorks.com
716.856.9675
john@kegworks.com

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация