QQ网名大全

怎样用php判断用户填写文本框非空值个数?,不建议用js,我还要用php做程序处理。谢谢大侠,在等

你的input的表单的name这样定义:text[],这个是一个数组,接收的时候$post = $_POST['text'];

<?php

/*
==========================================================
还是直接给你上代码更好,复制到你的运行环境执行就看到效果了
==========================================================
*/

//接收
if(isset($_POST['send'])){

    $post = $_POST['text'];
    echo count(array_filter($post, "unset_null")); //这里得出表单中的非空项的个数为5个
   
}

//删除数组中的空项
function unset_null($val){

    if($val == ''){
        return false;
    }

    return true;
}

?>

<form action="" method="post">
<input type="text" name="text[]" value="sscdcd" /><br />
<input type="text" name="text[]" value="sscdcd" /><br />
<input type="text" name="text[]" value="" /><br />
<input type="text" name="text[]" value="sscdcd" /><br />
<input type="text" name="text[]" value="sscdcd" /><br />
<input type="text" name="text[]" value="" /><br />
<input type="text" name="text[]" value="sscdcd" /><br />

<input type="submit" name="send" value="提交" />
</form>
佚名
2024-06-07 16:06:29
最佳回答
类似问题(10)