[英]PHP casting not working
Hi I am a newbie and trying to fixing a tiny problem since 24hrs but still no luck. 嗨,我是新手,自24小时以来一直试图解决一个小问题,但仍然没有运气。
<?php
$MOBILE=7372739;
$PASSWORD="some_pass";
$PASSWORD=(string)$PASSWORD;
$MOBILE=(string)$MOBILE;
//even tried $MOBILE="".$MOBILE; and $MOBILE="$MOBILE";
if(!(isset($PASSWORD)&& !empty($PASSWORD) && strlen($PASSWORD<=50))){
die("break1");
}
if(!(isset($MOBILE)&& !empty($MOBILE) && strlen($MOBILE<=50))){
die("break2");
}
?>
OUTPUT: break2 输出:break2
If I am using string $MOBILE="xyz";
如果我使用字符串$MOBILE="xyz";
not getting break2. 没有休息2。
Why always getting break2? 为什么总是得到break2? Please help. 请帮忙。 Thank you 谢谢
You are checking to see if $MOBILE is smaller than 50, and it is, so the script dies, the < needs to be a > (in one scenario of what you may want), see below 您正在检查$ MOBILE是否小于50,并且是否小于50,因此脚本消失了,<必须为>(在您可能需要的一种情况下),请参见下文
<?php
$MOBILE=7372739;
$PASSWORD="some_pass";
$PASSWORD=(string)$PASSWORD;
$MOBILE=(string)$MOBILE;
//even tried $MOBILE="".$MOBILE; and $MOBILE="$MOBILE";
if(!(isset($PASSWORD)&& !empty($PASSWORD) && strlen($PASSWORD<=50))){
die("break1");
}
if(!(isset($MOBILE)&& !empty($MOBILE) && strlen($MOBILE>=50))){
die("break2");
}
?>
But that's not your problem is it? 但这不是你的问题吗?
You are additionally turning $MOBILE into a string right there in your code, and strlen checks the string length. 您还需要在代码中将$ MOBILE变成字符串,然后strlen检查字符串长度。 If you want to check the value of it and not the length of the string, remove $MOBILE=(string)$MOBILE;
如果要检查它的值而不是字符串的长度,请除去$MOBILE=(string)$MOBILE;
and remove the strlen from the mobile check and then you can switch that $MOBILE sign back to < 并从移动支票中删除该strlen, 然后可以将该$ MOBILE标志切换回<
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.