Variable help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dezzik
Forum Newbie
Posts: 1
Joined: Tue Oct 12, 2010 3:18 am

Variable help

Post by dezzik »

Hi, I'm looking for a solution to my problems. I want to search a variable to see if it contains a certain string amongst others. This is basically what I mean:
Let's say

Code: Select all

$names = "Fred, Tom, Jill, Alex";
If I wanted to check if the variable contains "Alex" or not, how would I proceed?
EDIT: Sorry, I forgot strpos. :banghead: Please close this.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Variable help

Post by requinix »

dezzik wrote:Hi, I'm looking for a solution to my problems.
Aren't we all?


What's probably better for you is to split the string into bits and search for the bit you want. strpos will give you a false positive with something like "red".
Post Reply