我有以下php代码,我似乎无法正常工作:
<?php
if($_GET['sizex'] == null) {
$sizex = 200;
} else {
$sizex = $_GET['sizex']; // This is the problematic line
}
?>
当我尝试运行它时,我收到以下错误:
PHP Parse error: syntax error, unexpected '}' in test.php on line 6
我发现$ _GET []会导致这种情况,因为如果我将其替换为 $ sizex = 1 等其他内容,则可以正常工作。是否有一些我无法看到的拼写错误,或者是否有一些我不知道的$ _GET特别之处?
的var_dump($ _ GET):
array(1) {
["sizex"]=>
string(1) "1"
}
答案 0 :(得分:2)
它适用于我,任何检查GET / POST存在isset()/empty()
总是好的
<?
$sizex = isset($_GET['sizex']) ? $_GET['sizex'] : 200;
?>
答案 1 :(得分:2)
此代码工作正常。那里没有语法错误。可能你有一些奇怪的隐形字符。尝试清除所有换行符,然后将其插回。