You are here: Re: [PHP] strpos with array? « PHP « IT news, forums, messages
Re: [PHP] strpos with array?

Posted by Merlin on 05/10/05 16:08

Burhan Khalid wrote:
> Merlin wrote:
>
>> Hi there,
>>
>> I am wondering if there is a function (I could not find) which does
>> the same thing like strpos does, but with an array.
>>
>> For example:
>>
>> $replace = array("picture", "pics");
>> $pos = strpos ($term, $replace);
>> //if ($pos !== false) {
>
> if (in_array($term,$replace)) {
>
>> $term = str_replace($replace, "", $term);
>> echo 'term without the word:'.$term;
>> }
>
>
> http://www.php.net/in_array
Actually this did not solve the problem, since this function is searching for
the exact phrase, but not within a string.

I solved it that way:
// try pictures
$replace = array("pictures", "picture", "bilder", "bild", "pic", "pics", "pix");
foreach($replace AS $try){
$pos = strpos ($term, $try);
if ($pos !== false) {
$term = str_replace($try, "", $term);
#echo 'yes'.$term.$pos; exit;
HEADER("Location:/index.php?search_for=".$term.""); exit;
}
}

Maybe it will be useful for somebody else.

Merlin

 

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

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