Link to home
Start Free TrialLog in
Avatar of rgb192
rgb192Flag for United States of America

asked on

if string contains a 1 or 2

if string contains a
1
or
2

do something

for example
hello1
contains a 1

42
contains a 2

34
nothing

32675
contains a 2
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gopakumarvr
gopakumarvr

if(  strpos($mystring, '1')  )
{
    echo "Contains 1";
}
else if(  strpos($mystring, '2')  )
{
    echo "Contains 2";
}
else
{
   echo "Does not contain 1 or 2";
}

Check out these functions also
stristr() - Case-insensitive strstr
strrchr() - Find the last occurrence of a character in a string
strpos()  - Find the position of the first occurrence of a substring in a string
strpbrk() - Search a string for any of a set of characters
preg_match() - RE match..
Avatar of rgb192

ASKER

thanks