Ampersand in String causing incorrect length/comparison

php, string, urldecode, urlencode

Solution

It appears that you have HTML ampersand character `&` in one of the string. You should use html_entity_decode before comparing strings:

if (html_entity_decode($str1) == html_entity_decode($str2)) {
    // ...
}

Live Demo: http://ideone.com/pkWEJC

Problem

I have two strings (which are supposed to be the same). One is pulled from an API result and one is entered by the user. I'm trying to compare them and failing. When I var_dump, I get the following: ``` var_dump($str1); var_dump($str2); string(21) "Software & Technology" string(25) "Software & Technology" ``` Notice the incorrect length of $str2. Anyone know what's going on here?

Original source

Related problems