• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 279
  • Last Modified:

variable type comparsion, ture or false (boolean)

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
lilyyan
Asked:
lilyyan
2 Solutions
 
etullyCommented:
Try strpos(); instead
0
 
etullyCommented:
or strrpos to find the last character.  But strripos isn't valid
0
 
AlexanderREnterprise Web DeveloperCommented:
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
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
etullyCommented:
Ignore everything I wrote.  Sorry, wasn't familiar with that command.
0
 
lilyyanAuthor Commented:
I just used stripos(), seem  result.
0
 
paradoxengineCommented:
Or even strrpos : http://www.php.net/strrpos 
0
 
AlexanderREnterprise Web DeveloperCommented:
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
 
etullyCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now