Objectmix
Tags Register Mark Forums Read

Array wildcard? : PHP

This is a discussion on Array wildcard? within the PHP forums in Programming Languages category; 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...


Object Mix > Programming Languages > PHP > Array wildcard?

Reply

 

LinkBack Thread Tools
  #1  
Old 04-25-2002, 12:56 PM
Junior Member
 
Join Date: Nov 2009
Posts: 0
Application Development is on a distinguished road
Default Array wildcard?

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

Reply With Quote
  #2  
Old 04-25-2002, 12:58 PM
Junior Member
 
Join Date: Nov 2009
Posts: 0
Application Development is on a distinguished road
Default Re: [PHP] Array wildcard?

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

Reply With Quote
  #3  
Old 04-25-2002, 01:13 PM
Junior Member
 
Join Date: Nov 2009
Posts: 0
Application Development is on a distinguished road
Default Re: [PHP] Array wildcard?

on 4/25/02 1:58 PM, Miguel Cruz at mnc@stoic.net 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!"

Reply With Quote
  #4  
Old 04-25-2002, 01:50 PM
Junior Member
 
Join Date: Nov 2009
Posts: 0
Application Development is on a distinguished road
Default Re: [PHP] Array wildcard?

In article <B8EDBF9C.CBB4%eurleif@buyer-brokerage.com>,
eurleif@buyer-brokerage.com (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!"


<http://php.net/preg-match>

--
CC
Reply With Quote
  #5  
Old 04-25-2002, 04:11 PM
Junior Member
 
Join Date: Nov 2009
Posts: 0
Application Development is on a distinguished road
Default Re: [PHP] Array wildcard?

On Thu, 25 Apr 2002, Leif K-Brooks wrote:
> on 4/25/02 1:58 PM, Miguel Cruz at mnc@stoic.net 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

Reply With Quote
Reply

Thread Tools



All times are GMT -5. The time now is 05:36 PM.