我有以下代码:
$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/测试具有相同模式的相同字符串时,它将变为有效:
请查看屏幕截图:
出了什么问题?
$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值是否相同或不是