Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP's '===' operator

Tags:

php

I have code as

$url = $_GET['q'];
$string = "search_text";
$pos = strpos($url, $string);

Then I use the following to check for the presence of the search_text in the URL. If it is present, I want it to hide the HTML fields

if ($pos !== true) {
  // Generate HTML elements
}

However it does not work. Basically, I want to hide certain HTML elements when search_text is present in the URL using the '===' operator for comparing the $pos generated during the strpos operation.

like image 385
user550265 Avatar asked Mar 21 '26 04:03

user550265


1 Answers

$pos!==true is exactly the opposite of what you want to test for: strpos() will never return true, but either a number or false.

Use

if ($pos === false)
like image 155
Pekka Avatar answered Mar 22 '26 18:03

Pekka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!