Skip to content
Advertisement

PHP strlen() and if statement not working correctly [closed]

I have a PHP form that when loads will get some variables. Not all variables are set. In the code I can see if the Variable has been defined by using strlen() and that seem to be working but when I apply an if statement it doesn’t seem to work? GetSettingValue() is a function to get the value in a file, the item in the file might not exist

the code I have tried is:

if (strlen(GetSettingValue("Latitude"))==0);{
logEntry("Lat== 0");
    }

Just prior to this statement I print the results of strlen(GetSettingValue(“Latitude”)) and it displays 0 (this is the expected result) And the logEntry gets processed.

But if I want to not enter the if statement I used:

if (strlen(GetSettingValue("Latitude"))!=0);{
logEntry("Lat== 0");
    }

and the results of strlen(GetSettingValue(“Latitude”)) right before the if statement shows 0 But the code will process the logEntry. It seems like the result of strlen() doesn’t matter?

Any ideas or a better method?

Advertisement

Answer

Just remove the ; semicolon after the parenthesis and it’ll work absolutely fine.

Correction:

if (strlen(GetSettingValue("Latitude"))!=0) { logEntry("Lat== 0"); }

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement