gpt4 book ai didi

PHP preg_match 返回 false

转载 作者:行者123 更新时间:2023-12-04 20:15:37 26 4
gpt4 key购买 nike

为什么在下面的代码中 PHP preg_match 返回 false?注意:我读过一些与我的问题同名的旧问题,但上下文不同

<html>
<head>
</head>
<body>
<?php
$str = "This is a test for PCRE.";
$ptrn = "This";
$preg_match_result_arr;
$preg_match_result = preg_match($ptrn, $str, $preg_match_result_arr);

if (1 === $preg_match_result)
{
echo "The pattern has matched in the string:<br/>".
"the match is $preg_match_result_arr[0]<br/>";
}
elseif (0 === $preg_match_result)
{
echo "The pattern has not matched in the string:<br/>";
}
elseif (false === $preg_match_result)
{
echo "An error has occured in matching<br/>";
}

?>
</body>
</html>

最佳答案

你的表达不正确,应该像这样用定界符包围。

$ptrn = '/This/';

关于PHP preg_match 返回 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11816582/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com