Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple PHP If Statement error

Tags:

php

I have a very simple IF statement...

if ($key == "listingURL" or 
     $key == "interiorColor" or 
     $key == "engine" or 
     $key == "transmission" or 
     $key == "stockNumber" or 
     $key == "VIN") {
          // Do thing
}

But I'm receiving an error...

[23-Apr-2015 13:12:01 UTC] PHP Parse error: syntax error, unexpected T_VARIABLE in xxx on line xxx

Which is this line...

 $key == "stockNumber" or

Is there a limit to the maximum amount of OR's, or am I missing something staring me right in the face?

like image 753
SoWizardly Avatar asked Apr 23 '15 13:04

SoWizardly


2 Answers

"Is there a limit to the maximum amount of OR's, or am I missing something staring me right in the face?"

No there isn't. The reason is because you have a hidden character:

$key == "transmission" or ? <= right there

enter image description here

Which is &#65279;

Being a Unicode ZERO WIDTH NO-BREAK SPACE character.

Rewrite:

if ($key == "listingURL" or 
     $key == "interiorColor" or 
     $key == "engine" or 
     $key == "transmission" or
     $key == "stockNumber" or 
     $key == "VIN") {
          // Do thing
}

Sidenotes:

As from the comments:

I'll confirm this as the correct answer as soon as the time limit is up! Thank you so much for the help. I use Sublime Text 3, is there some easy way to detect these hidden characters? – SoWizardly 19 mins ago

For Notepad++ there is a plugin called: HEX-Editor.

You can download it via: Extensions -> Plugin Manager -> Available. Just check the combo box for HEX-Editor and click install. After this you can change your file view to hexadecimal.

For Sublime Text there is also a plugin, which does the same.

like image 163
Funk Forty Niner Avatar answered Sep 28 '22 07:09

Funk Forty Niner


When i copy in other editor i get this remove it near stock number ? <=

if ($key == "listingURL" or 
     $key == "interiorColor" or 
     $key == "engine" or 
     $key == "transmission" or 
     $key == "stockNumber" or ? <=
     $key == "VIN") {
          // Do thing
}
like image 39
Rex Rex Avatar answered Sep 28 '22 08:09

Rex Rex