I am reading a text file line by line and each line has comma separated values. example
Name,Phone,URL,notavailable
The reading is fine and the script returns the lines correctly. The last value has “available” or “notavailable”.
I am exploding a line like this
$sections = explode(",", $line);
and it returns
Array
(
[0] => Name
[1] => Phone
[2] => URL
[3] => notavailable
)
I can get values using
$sections[0], $sections[1] etc.
And they display just fine. But the problem occurs when I try to compare the last value.
$check = $sections[3];
if($check=="notavailable")
{Do something }
else {Do something else}
But the if statement always returns false. I could not figure that out. Tried so many time. It will be so much helpful somebody can point out the error in my script.
Thanks in advance.
You need to do a little debugging. Throw in a line like
If you print it out in quotes like that, you’ll probably see there are leading/trailing spaces. If that is the case, a simple call to
trim()will take care of it.