rob.m rob.m - 1 month ago 8
PHP Question

Name in json has space and doesn't match with a variable

In PHP I do:

the_field('country');


That gives me:
United States Of America


In the json I have:

"sovereignt": "United States of America",


The 2 names should match but they don't, I believe is due to the white space in between the words. The reason why I believe that is that if i check with
"Bolivia"
or
"Canada"
or
"Italy"
I have no problems.

EDIT


I had O instead of O - accepting the answer for future users

Answer

It's because O != o (i.e. upper vs. lower case). When doing the comparison, try converting both to lower case (using PHP's strtolower() function):

if( strtolower(the_field('country')) == strtolower($json->soverignt) )
Comments