Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 斯特伦工作不正常_Php_Forms_Strlen - Fatal编程技术网

Php 斯特伦工作不正常

Php 斯特伦工作不正常,php,forms,strlen,Php,Forms,Strlen,我正在创建一个简单的注册表 我的问题是,当我使用strlen函数时,它不是真的 当我输入数字作为密码时,它不会显示任何内容 当我输入not number时,即使超过6个字符,它也会显示消息 <?php if (isset($_POST['signup'])) { $fname = $_POST['fname']; $lname = $_POST['lname']; $phone = $_POST['phone-number']; $address

我正在创建一个简单的注册表 我的问题是,当我使用strlen函数时,它不是真的 当我输入数字作为密码时,它不会显示任何内容 当我输入not number时,即使超过6个字符,它也会显示消息

 <?php
 if (isset($_POST['signup'])) {
     $fname = $_POST['fname'];
     $lname = $_POST['lname'];
     $phone = $_POST['phone-number'];
     $address = $_POST['address'];
     $password = $_POST['password'];
     $cpassword = $_POST['cpassword'];
 }
 if (isset($password)) {
     if (strlen($password < 6)) {
         $password_err = "password must be at least 6 characters";
     }
 }

 ?>
 <?php
 if (isset($password_err)){
 echo $password_err;
 }
 ?>
你使用的方式不好。您应该使用strlen$变量,然后在您的案例中使用所需的比较,<6

因此,代码上的行应该是:

if (strlen($password) < 6) { ... }
你使用的方式不好。您应该使用strlen$变量,然后在您的案例中使用所需的比较,<6

因此,代码上的行应该是:

if (strlen($password) < 6) { ... }
用这个

 if (isset($password)) {
     if (strlen($password) < 6) {
         $password_err = "password must be at least 6 characters";
     }
 }
只不过是放错了右括号

用这个

 if (isset($password)) {
     if (strlen($password) < 6) {
         $password_err = "password must be at least 6 characters";
     }
 }
只是把括号放错地方了

if (strlen($password < 6)) {

改变

if (strlen($password < 6)) {


我相信斯特伦方法的使用有一个小错误。其中一个支架的位置错误。将带有strlen的if语句更改为:

if (strlen($password) < 6) {
     $password_err = "password must be at least 6 characters";
 }

$password后面应该有一个右括号。

我认为在使用strlen方法时有一个小错误。其中一个支架的位置错误。将带有strlen的if语句更改为:

if (strlen($password) < 6) {
     $password_err = "password must be at least 6 characters";
 }

$password后面应该有一个右括号。

Strlen的使用方式不对。你可以这样说:

if (strlen($password < 6)) {
if (strlen($password) < 6)) {
当您想这样使用它时:

if (strlen($password < 6)) {
if (strlen($password) < 6)) {
下面简要解释一下为什么会这样:

$length = strlen($password); // Will output a number so if password is 'password', it will output '8'.

// So lets add that strlen to the if statement
if ($length < 6) { // This will compare that number that $length output, to 6.
    # Do something
}

斯特伦被错误地使用了。你可以这样说:

if (strlen($password < 6)) {
if (strlen($password) < 6)) {
当您想这样使用它时:

if (strlen($password < 6)) {
if (strlen($password) < 6)) {
下面简要解释一下为什么会这样:

$length = strlen($password); // Will output a number so if password is 'password', it will output '8'.

// So lets add that strlen to the if statement
if ($length < 6) { // This will compare that number that $length output, to 6.
    # Do something
}

错误在表达式中:

strlen($password < 6)
true转换为“1”,false转换为空字符串


相应地,返回1或0。

错误在表达式中:

strlen($password < 6)
true转换为“1”,false转换为空字符串


因此,返回1或0。

我使用的是PHP7.4,OP的方法有效。 然而,升级到PHP8后,它停止了工作

更让人困惑的是,在PHPStorm中,strlen后面显示为“string”


因此,您认为,因为它显示了预期不多的数据格式,所以它将是正常的。

我使用的是PHP7.4,OP的方法工作正常。 然而,升级到PHP8后,它停止了工作

更让人困惑的是,在PHPStorm中,strlen后面显示为“string”

因此,您认为,因为它显示了很少期望的数据格式,所以它将是正常的。

strlen不是多字节保存。所以任何像ö这样的角色都会抛出。请改用mb_strlen。strlen不是多字节保存。所以任何像ö这样的角色都会抛出。改用mb_strlen。