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?
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)) {
// ...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With