Solved

if string contains a 1 or 2

Posted on 2012-12-27
3
235 Views
Last Modified: 2012-12-27
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
0
Comment
Question by:rgb192
3 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 38725799
if (strpos(theString, "1") || strpos(theString, "2")) {
    // do something
}

Open in new window

0
 

Expert Comment

by:gopakumarvr
ID: 38726131
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..
0
 

Author Closing Comment

by:rgb192
ID: 38726148
thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question