Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strpos 1

Status
Not open for further replies.

dle46163

IS-IT--Management
Jul 9, 2004
81
US
Hey all,

I've got a string like this:
$play_days="0123456";

I need to search for individual numbers in the string. If the number is not found, I simply echo a statement. Everything is fine except when the number found resides in the zero position in the string. I've tried the following things:

if (strpos($play_days,'0')!=false){echo "Not Found!";}
if (strpos($play_days,'0')!=""){echo "Not Found!";}

Neither of which work for the digit in the zero position. Can anyone give me a hand with this?

thanks!

 
Shouldn't it be ===FALSE for it to be not found?

Otherwise if its different to False, that means it did find it inside the string? it has a valid position in the string.

Code:
if (strpos($play_days,'0') !== false){echo "Not Found!";}

Will only be true if it is found, so it doesn;t make uch sense

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thanks jpadie, works like a charm!

-dle
 
Hello all,

If a function gives back a logical value you can do it also on the next way:

if (!strpos($play_days,'0')){echo "Not Found!";}

See the exclamation mark!

Regards,
Solo1234
 
yes - if you can guarantee it's false.

but many functionals also return a zero, which, without type verification (===) is considered false. strpos can easily return a zero if the matched string is at the start of the subject.
 
Hello jpadie,

You'r right but I was talking about a logical responce of a function.

Solo1234
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top