Solved

if string contains a 1 or 2

Posted on 2012-12-27
3
230 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 74

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now