如何解决strlenphp没有给出正确的结果
我尝试使用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;
?>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。