Reputation:
I have this URL "https://www.example.com/thymus_vulgaris?tag=Oil&page=2" where I get /thymus_vulgaris?tag=Oil&page=2 from $_SERVER['REQUEST_URI'] in php and I have also saved the same URL in database that I am getting in a variable $abc = /thymus_vulgaris?tag=Oil&page=2 you can see both URL URI is same I am writing this code. but comparison is not working please see the screenshot value for better understand
foreach ($redirects as $redirectlink) {
if('/thymus_vulgaris?tag=Oil&page=2' == $redirectlink['title']){
die;
}
}
if I do print_r($redirects) I got this array results see below
Array
(
[0] => Array
(
[title] => /thymus_vulgaris?tag=Oil&page=2
[url] => essential-oils
)
[1] => Array
(
[title] => /products/diffusers
[url] => diffusers
)
[2] => Array
(
[title] => /essential-oils/Essential-Oil-Kits/sleep_and_breathe
[url] => essential-oils
)
[3] => Array
(
[title] => /Solum%20Lux%20Telum
[url] => essential-oils
)
[4] => Array
(
[title] => /organic-boswellia-serrata
[url] => essential-oils
)
[5] => Array
(
[title] => /faqs
[url] => FAQ
)
[6] => Array
(
[title] => /clearance/refurbished-replacement-bottles/amp
[url] => accessories/bottles-and-caps/amp
)
[7] => Array
(
[title] => /refurbished-replacement-bottles/amp
[url] => accessories/bottles-and-caps/amp
)
)
if you see first array value is same as request $_SERVER['REQUEST_URI'] value. Can anybody help me quickly?
Upvotes: 1
Views: 197
Reputation: 16997
I guess probably some invisible char, because of which ==
resulting false
,
For example : DEMO
$ php -r '$f1="foo"; $f2="foo\0"; echo $f1.PHP_EOL; echo $f2.PHP_EOL; var_dump($f1); var_dump($f2); var_dump($f1==$f2);'
foo
foo
string(3) "foo"
string(4) "foo"
bool(false)
As you can see above, $f1
and $f2
both are not equal, but looks like same.
Output :
Upvotes: 1