Re: [PHP] Array wildcard?

2002-04-25 Thread Miguel Cruz

On Thu, 25 Apr 2002, Leif K-Brooks wrote:
> on 4/25/02 1:58 PM, Miguel Cruz at [EMAIL PROTECTED] wrote:
>> On Thu, 25 Apr 2002, Leif K-Brooks wrote:
>>> Is there some array wildcard I can use?  In other words, I have an
>>> array. Is there any wildcard function/character that will let me test
>>> to see if a string matches anything in that array?  Thanks
>> 
>> http://php.net/in_array ?
> 
> One more question.  Is  there any way to use this with part of a string?
> Example:
> function checkfruitlove($string){
> $fruitarray = array("apples","oranges");
> if($string == "I love ".in_array($fruitarray)."!"){
> $return = "I do too!";
> }else{
> $return = "I don't!";
> }
> return $return;
> }
> $answer = chechfruitlove("I love apples!"); //returns "I do too!"
> $answer = chechfruitlove("I love oranges!"); //returns "I do too!"
> $answer = chechfruitlove("I love pears!"); //returns "I don't!" 

How about:

$fruitarray = array("apples","oranges");
if (preg_match('/I love (' . join('|', $fruitarray) . ')/', $string))
 ...

I haven't tested it but it seems reasonable.

miguel


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




Re: [PHP] Array wildcard?

2002-04-25 Thread CC Zona

In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Leif K-Brooks) wrote:

> One more question.  Is  there any way to use this with part of a string?
> Example:
> function checkfruitlove($string){
> $fruitarray = array("apples","oranges");
> if($string == "I love ".in_array($fruitarray)."!"){
> $return = "I do too!";
> }else{
> $return = "I don't!";
> }
> return $return;
> }
> $answer = chechfruitlove("I love apples!"); //returns "I do too!"
> $answer = chechfruitlove("I love oranges!"); //returns "I do too!"
> $answer = chechfruitlove("I love pears!"); //returns "I don't!" 



-- 
CC

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




Re: [PHP] Array wildcard?

2002-04-25 Thread Leif K-Brooks

on 4/25/02 1:58 PM, Miguel Cruz at [EMAIL PROTECTED] wrote:

On Thu, 25 Apr 2002, Leif K-Brooks wrote:
> Is there some array wildcard I can use?  In other words, I have an array.
> Is there any wildcard function/character that will let me test to see if a
> string matches anything in that  array?  Thanks

http://php.net/in_array ?

miguel


One more question.  Is  there any way to use this with part of a string?
Example:
function checkfruitlove($string){
$fruitarray = array("apples","oranges");
if($string == "I love ".in_array($fruitarray)."!"){
$return = "I do too!";
}else{
$return = "I don't!";
}
return $return;
}
$answer = chechfruitlove("I love apples!"); //returns "I do too!"
$answer = chechfruitlove("I love oranges!"); //returns "I do too!"
$answer = chechfruitlove("I love pears!"); //returns "I don't!" 



Re: [PHP] Array wildcard?

2002-04-25 Thread Miguel Cruz

On Thu, 25 Apr 2002, Leif K-Brooks wrote:
> Is there some array wildcard I can use?  In other words, I have an array.
> Is there any wildcard function/character that will let me test to see if a
> string matches anything in that  array?  Thanks

http://php.net/in_array ?

miguel


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




[PHP] Array wildcard?

2002-04-25 Thread Leif K-Brooks

Is there some array wildcard I can use?  In other words, I have an array.
Is there any wildcard function/character that will let me test to see if a
string matches anything in that  array?  Thanks


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