php - 简单的 PHP If 语句错误

标签 php

我有一个非常简单的 IF 语句...

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

但是我收到一个错误...

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

这是哪一行...

 $key == "stockNumber" or

OR 的最大数量是否有限制,或者我是否遗漏了一些正对着我的东西?

最佳答案

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

不,没有。原因是因为你有一个隐藏角色:

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

enter image description here

这是

成为 Unicode ZERO WIDTH NO-BREAK SPACE性格。

重写:

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

旁注:

来自 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

对于 Notepad++有一个插件叫做:HEX-Editor

您可以通过以下路径下载它:扩展 -> 插件管理器 -> 可用。只需选中 HEX-Editor 的组合框,然后单击安装。在此之后,您可以将文件 View 更改为十六进制。

对于 Sublime Text还有一个 plugin ,这也是一样的。

关于php - 简单的 PHP If 语句错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29824738/

相关文章:

php - mysql问题与添加列

php - 使用后清除 session 变量

php - 从 .txt 文件中读取数字并在 PHP 中的 foreach 循环中打印数字的算法

php - 为什么是 "Allowed memory size exhausted"?

php - 使用 PHP DOM 的 removeChild 不起作用

php - 尝试将 mysql_* 重写为 pdo

php - CodeIgniter MySQL 查询使用过多内存 - 如何使用 MySQL 的 SSCursor?

php - 格式化sql查询的十进制输出

php - 相同键的特定 mysql_fetch_array 总和值

php - 编码Json请求的问题