Home  >  Article  >  Backend Development  >  为什么这个总是第一个不合法?

为什么这个总是第一个不合法?

WBOY
WBOYOriginal
2016-07-06 13:51:45831browse

比如我第一个333333 第二个输入3333333333333 第一个应该是合法的第二个应该不合法 但是为什么总是提示第一个不合法?

<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>

回复内容:

比如我第一个333333 第二个输入3333333333333 第一个应该是合法的第二个应该不合法 但是为什么总是提示第一个不合法?

<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>

你第二个变量是$b,根本没用上。怎么可能报不合法?

忘了 不能用=了

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn