1

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?

2
  • How do you know comparison is not working? die("it worked"); maybe? Commented Jul 20, 2018 at 18:04
  • I tried what you posted here and it worked for me. I thought maybe some character was messing it up (/ ? &) but all is ok. Are you certain you do not have any HTML entities that appear as & but are actually & anywhere? Add var_dump($redirectlink['title']); just before the if. Commented Jul 20, 2018 at 18:05

1 Answer 1

1

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 :

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.