[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

variable type comparsion, ture or false (boolean)

Posted on 2007-08-06
8
Medium Priority
?
274 Views
Last Modified: 2013-11-05
Hello,
I'm using this string function : strripos();
------------------------------
$serachString="Hello world ";
$findString ="test";
$found =true;
if (strripos(strtolower($serachString), strtolower($findString) ) ==false)
 $found  = false;
---------------------------
Is there any error in the above code (the if statment )?

Any suggestion is highly appreciated,
lilyyan


0
Comment
Question by:lilyyan
8 Comments
 
LVL 2

Expert Comment

by:etully
ID: 19640963
Try strpos(); instead
0
 
LVL 2

Expert Comment

by:etully
ID: 19640978
or strrpos to find the last character.  But strripos isn't valid
0
 
LVL 11

Accepted Solution

by:
AlexanderR earned 800 total points
ID: 19640985
Yes, it should be tripple equal sign, because this is a case for a strict comparison.

$serachString="Hello world ";
$findString ="test";
$found =true;
if (strripos(strtolower($serachString), strtolower($findString) ) === false)
 $found  = false;
0
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!

 
LVL 2

Expert Comment

by:etully
ID: 19640987
Ignore everything I wrote.  Sorry, wasn't familiar with that command.
0
 

Author Comment

by:lilyyan
ID: 19640991
I just used stripos(), seem  result.
0
 
LVL 9

Expert Comment

by:paradoxengine
ID: 19640995
Or even strrpos : http://www.php.net/strrpos 
0
 
LVL 11

Assisted Solution

by:AlexanderR
AlexanderR earned 800 total points
ID: 19641089
There is no difference in what you use, stripos, strrpos, whatever.  Its the === that matters.

all those functions return 0 or a 1. 0 is not equal to false using regular methods, because PHP would convert them to string and "0" is not equal to "false".  But if you use === sign, then variable types are preserved and 0 indeed equals to false.
0
 
LVL 2

Expert Comment

by:etully
ID: 19641571
AlexanderR:  I didn't do anything in this thread except confuse the situation by making a few dumb mistakes.  You deserve all the points for this one.  If you know how I can transfer my points to you on this one,  I'll gladly do that.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
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.
Suggested Courses
Course of the Month20 days, 10 hours left to enroll

867 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