PHP:preg_match总是返回false

问题描述 投票:0回答:1

我有以下代码:

$pattern = "/[A-Z0-9]{8}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{12}/";
        if( ! preg_match( $pattern, $profile_Id ) ) {
            $failed_json = json_encode(array(
                "user" => array(
                    "status_code" => "420",
                    "status"      => "Failed",
                    "message"     => "Invalid Platform ID."
                ),
            ));

            echo $failed_json;
        } else {
           // do stuff here
        }

我以$profile_Id输入12E69FF4-6CB1-5427-83D5-D8F775160699,该报告为“无效”。

但是当我在https://regex101.com/测试具有相同模式的相同字符串时,它将变为有效:

请查看屏幕截图:

enter image description here

出了什么问题?

php regex preg-match
1个回答
0
投票
  $pattern = "/[A-Z0-9]{8}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{12}/";
  if( ! preg_match( $pattern, '12E69FF4-6CB1-5427-83D5-D8F775160699' ) ) {
  $failed_json = json_encode(array(
    "user" => array(
        "status_code" => "420",
        "status"      => "Failed",
        "message"     => "Invalid Platform ID."
    ),
   ));

   echo $failed_json;
  } else {

       echo "hello";
   }

您的代码工作正常,请检查您的$ profile_Id值是否相同或不是

© www.soinside.com 2019 - 2024. All rights reserved.