Simple PHP If Statement Error

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 get an error message ...

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

What is this line ...

  $key == "stockNumber" or 

Is there a limit on the maximum number of ORs, or am I missing something that concerns me directly in the face?

+5
source share
5 answers

"Is there a limit on the maximum number of ORs, or am I missing something that looks right in my face?"

No no. The reason is because you have a hidden character:

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

enter image description here

What is &#65279;

Be unicode character ZERO WIDTH NO-BREAK SPACE .

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 will confirm this as the correct answer as soon as the deadline expires! Thank you so much for your help. I am using Sublime Text 3, is there an easy way to detect these hidden characters? - SoWizardly 19 min ago

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

You can download it through: Extensions → Plugin Manager → Available. Just set the combo box for the HEX-Editor and click "Install." After that, you can change the appearance of the file to hex.

There is also a plugin for Sublime Text that does the same.

+20
source

When I copy in another editor, do I get it to delete it near the stock number? & L; =

 if ($key == "listingURL" or $key == "interiorColor" or $key == "engine" or $key == "transmission" or $key == "stockNumber" or ? <= $key == "VIN") { // Do thing } 
+2
source

Copy of comment: One sentence: use in_array or something else to check the value of a variable for several values:

 $values = array( 'listingURL', 'interiorColor'); if ( in_array( $key, $values) ) { //do stuff 
+1
source

try something like this

 $arr = array("listingURL","interiorColor","engine","transmission","stockNumber","VIN"); if(in_array($key, $arr)) { // do something } 

this is a much more efficient way of doing things

0
source

Remove unwanted characters from $key == "transmission" or ? <= $key == "transmission" or ? <=

 ? <=` This causes the problem 
0
source

All Articles