这有什么问题呢?如果$forwardformat不为空,"if语句“中的代码就会运行,但如果$forwardformat为空,"else”代码就不会运行。有什么想法吗?!
while ($row = mysql_fetch_array($forwardresult)) {
$forward = $row["id"];
$forwardformat = str_replace(" ","",$forward);
if (!empty($forwardformat)) {
echo 'Exploring moves us <a href="casestudy.php?id=';
echo $forwardformat;
echo '">forward</a>';
}
else {
echo "forward";
}
}发布于 2009-07-14 08:50:48
查看认为为空的事物列表
如果var具有非空和非零值,则返回FALSE。
The following things are considered to be empty:
■"" (an empty string)
■0 (0 as an integer)
■"0" (0 as a string)
■NULL
■FALSE
■array() (an empty array)
■var $var; (a variable declared, but without a value in a class)发布于 2009-07-14 08:16:22
如果$forwardformat不为空,它确实应该输入if语句。
发布于 2009-07-14 09:06:10
我认为,你的问题是这一行:
$forwardformat = str_replace(" ","",$forward);这只与空格字符匹配。制表符、换行符等不会被替换(并且在回显结果时不会真正显示在(html-)输出中。所以我建议你试一试
$forwardformat = preg_replace('/\s+/','',$forward);HTH
阿格尔巴格
https://stackoverflow.com/questions/1124110
复制相似问题