Home > Backend Development > PHP Tutorial > Why is this always illegal first?

Why is this always illegal first?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-06 13:51:45
Original
917 people have browsed it

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>
Copy after login
Copy after login

Reply content:

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>
Copy after login
Copy after login

Your second variable is $b, which is not used at all. How could the report be illegal?

Forgot it can’t be used=

Related labels:
php
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template