5

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?

5
  • 1
    One suggestion: Use in_array or something else to check a value of a variable against multiple values: $values = array( 'listingURL', 'interiorColor'); if ( in_array( $key, $values) ) { //do stuff Commented Apr 23, 2015 at 13:21
  • 1
    Or may be you can use || in place of or Commented Apr 23, 2015 at 13:22
  • Use an hexeditor. There's a stray BOM in there <FEFF>. Commented Apr 23, 2015 at 13:22
  • @SunilPachlangia, tried earlier but no difference! Commented Apr 23, 2015 at 13:22
  • @SoWizardly an additional edit was made to my answer in regards to plugins Commented Apr 23, 2015 at 13:59

5 Answers 5

22

"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.

Sign up to request clarification or add additional context in comments.

14 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 Well, I use Notepad++ and that came up as an Unicode. I have never used Sublime, but there's probably an viewing option in it.
@BeatAlex strangely enough, I started off with regular Notepad, noticed the little square at the end of the line, slapped into Notepad++ and also my HTML page editor to confirm.
@SoWizardly I found this Q&A stackoverflow.com/q/20356784 and packagecontrol.io/packages/Unicode%20Character%20Highlighter and stackoverflow.com/a/20999477 - there were more links while Googling "how to detect unicode characters with sublime". I hope it helps.
@Fred-ii- Thanks for all your help! I was having some issues getting a .csv file importer to work, and it looks like that character came from me copy+pasting...which lead me to realize that's what was causing the problem...I ended up finding a nice PHP script that strips these characters from strings, and now everything works as intended!
|
2

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
}

Comments

0

try something like this

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

this is much more effective way of doing things

Comments

0

Copy of comment: One suggestion: Use in_array or something else to check a value of a variable against multiple values:

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

Comments

0

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

? <=` This causes the problem

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.