For example, my first input is 333333 and the second input is 3333333333333. The first one should be legal and the second one should be illegal. But why does it always prompt that the first one is illegal?
<code> <form method="post"> <input type="text" name="name"> <input type="text" name="name2"> <button type="submit">提交</button> </form> <?php $reg1='/^[1-9]\d{5,9}$/i'; $reg2='/\w{30,100}/'; $a=$_POST['name']; $b=str_replace(" ","",$_POST['name2']); if(preg_match($reg1, $a)){ $nm=1; }else{ $nm=2; } if(preg_match($reg2, $b)){ $cm=1; }else{ $cm=2; } if($nm=2){ echo "1buhefa"; }else if($cm=2){ echo "2buhefa"; }else{ echo "yes"; } ?> </code>
For example, my first input is 333333 and the second input is 3333333333333. The first one should be legal and the second one should be illegal. But why does it always prompt that the first one is illegal?
<code> <form method="post"> <input type="text" name="name"> <input type="text" name="name2"> <button type="submit">提交</button> </form> <?php $reg1='/^[1-9]\d{5,9}$/i'; $reg2='/\w{30,100}/'; $a=$_POST['name']; $b=str_replace(" ","",$_POST['name2']); if(preg_match($reg1, $a)){ $nm=1; }else{ $nm=2; } if(preg_match($reg2, $b)){ $cm=1; }else{ $cm=2; } if($nm=2){ echo "1buhefa"; }else if($cm=2){ echo "2buhefa"; }else{ echo "yes"; } ?> </code>
Your second variable is $b
, which is not used at all. How could the report be illegal?
Forgot it can’t be used=