Re: [PHP] strpos with array?

2005-05-13 Thread Marek Kilimajer
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


Re: [PHP] strpos with array?

2005-05-12 Thread Burhan Khalid
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.

2. You should always pass a full url (ie, with the scheme and host) to 
the Location header.

3. You need a space after Location:
4. There is no need for . at the end of your Location: string.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] strpos with array?

2005-05-10 Thread Merlin
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) {
   $term = str_replace($replace, , $term);
   echo 'term without the word:'.$term;
}
This does of course not work since strpos does not take arrays.
Thank you for any help,
Merlin
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] strpos with array?

2005-05-10 Thread Marek Kilimajer
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) {
   $term = str_replace($replace, , $term);
   echo 'term without the word:'.$term;
}
This does of course not work since strpos does not take arrays.
Thank you for any help,
Merlin
http://www.php.net/array_search
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] strpos with array?

2005-05-10 Thread Shaw, Chris - Accenture

Hello,

Have you tried using array_keys or array_search for finding an occurrence in
an array?

HTH.

Chris.

-Original Message-
From: Merlin [mailto:[EMAIL PROTECTED]
Sent: 10 May 2005 11:11
To: php-general@lists.php.net
Subject: [PHP] strpos with array?


*

This e-mail has been received by the Revenue Internet e-mail service.

*

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) {
   $term = str_replace($replace, , $term);
   echo 'term without the word:'.$term;
}

This does of course not work since strpos does not take arrays.

Thank you for any help,

Merlin

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







This message has been delivered to the Internet by the Revenue Internet e-mail 
service

*

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



Re: [PHP] strpos with array?

2005-05-10 Thread Burhan Khalid
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
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] strpos with array?

2005-05-10 Thread Merlin
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
Thank you! That was exactly what I was searching for.
Merlin
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] strpos with array?

2005-05-10 Thread Merlin
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
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php