Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.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_Regex_Debugging - Fatal编程技术网

Php 为什么';我的赛前工作不好吗?

Php 为什么';我的赛前工作不好吗?,php,regex,debugging,Php,Regex,Debugging,以下是我的PHP脚本: <?php if (isset($_POST['account'])) { $str = $_POST[account]; if ( !preg_match( "^[0-9]+$", $str )) { print "<p class=\"fadeout\" style=\"color:rgba(240, 240, 0, 1.0);\" >Enter numbers only!</p>"; }

以下是我的PHP脚本:

<?php
if (isset($_POST['account']))
{
    $str = $_POST[account];
    if ( !preg_match( "^[0-9]+$", $str ))
    {
        print "<p class=\"fadeout\" style=\"color:rgba(240, 240, 0, 1.0);\" >Enter numbers only!</p>";
    }
    else
    {
        exec('"cmd /c echo weee!"');
        print "<p class=\"fadeout\" style=\"color:rgba(240, 240, 0, 1.0);\" >Your account has been added.</p>";
    }
}
else {
    if (isset($_POST['account']) || $account == "") {
        print "<form method=\"post\"><p>Enter your account number below.</p>";
        print "<input name=\"account\" type=\"text\" size=\"15\" maxlength=\"7\"><input value=\"Send\" type=\"submit\"></form>";
    }
}
?>

我觉得你的正则表达式不对。试试这个:

if (!preg_match("/^[0-9]+$/", $str))

在我看来,你的正则表达式是不对的。试试这个:

if (!preg_match("/^[0-9]+$/", $str))

这看起来像是post输入的一个简单语法错误

if (isset($_POST['account']))
            {
                $str = $_POST[account];
应改为

if (isset($_POST['account']))
            {
                $str = $_POST['account'];

这看起来像是post输入的一个简单语法错误

if (isset($_POST['account']))
            {
                $str = $_POST[account];
应改为

if (isset($_POST['account']))
            {
                $str = $_POST['account'];
你有两个问题:

  • 您没有正确地从
    $\u POST
    获取值
  • 不正确:
    $str=$\u POST[account]

    正确:
    $str=$\u POST['account']

  • 你的正则表达式是错误的
  • 您可以在此处测试正则表达式:

    如果希望它只接受数字,请更改此行:

    if ( ! preg_match( "^[0-9]+$", $str ))
    
    为此:

    if ( ! preg_match( "(^[0-9]+$)", $str))
    
    你有两个问题:

  • 您没有正确地从
    $\u POST
    获取值
  • 不正确:
    $str=$\u POST[account]

    正确:
    $str=$\u POST['account']

  • 你的正则表达式是错误的
  • 您可以在此处测试正则表达式:

    如果希望它只接受数字,请更改此行:

    if ( ! preg_match( "^[0-9]+$", $str ))
    
    为此:

    if ( ! preg_match( "(^[0-9]+$)", $str))
    

    1请自己做研究,自己检查代码或自己运行代码,并检查错误日志

    $account

    尚未在此脚本中设置,并且

    isset($\u POST['account'])

    已为false,因为在检查它是否为true之后,它已位于false语句中,并且您可以使用ifelse或switch语句


    1请自己进行研究,自己检查代码或自己运行代码,并检查错误日志

    $account

    尚未在此脚本中设置,并且

    isset($\u POST['account'])

    已为false,因为在检查它是否为true之后,它已位于false语句中,并且您可以使用ifelse或switch语句


    PHP将自动将不带引号的标识符转换为字符串(如果它们不是常量的名称)。PHP将自动将不带引号的标识符转换为字符串(如果它们不是常量的名称)。您应该在代码中启用带有
    错误报告(E\u ALL)的警告。然后,您将从格式不正确的regexp中得到一条错误消息。您应该使用
    error\u reporting(E\u ALL)在代码中启用警告。然后,您将从格式不正确的regexp中得到一条错误消息。