Re: strpos with array?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Burhan Khalid wrote:
Merlin wrote:

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;


1. All functions in PHP are lowercase. Do not UPPERCASE your functions. Its Just Not Right.

Case in function names does not matter. It does matter in variable names.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux