问题描述
我尝试使用php进行简单的长度检查。发布的值为12/26,代码为:
echo "length:" . strlen($this->request->post["expiration"]);
if (strlen($this->request->post["expiration"]==5)){
echo "correct";
}else{
echo "wrong";
}
exit;
结果是:
length:5 wrong
请问我的错误是什么?
解决方法
请注意以下行:if (strlen($this->request->post["expiration"]==5))
。
您基本上是想在整个表达式上使用strlen。尝试以下方法:if (strlen($this->request->post["expiration"])==5)
/* Please see the code if it works */
<?php
echo "length:" . strlen($this->request->post["expiration"]);
$a= strlen($this->request->post["expiration"]);
if ($a==5))
{
echo "correct";
}else
{
echo "wrong";
}
exit;
?>