0

我正在尝试使用正则表达式在字符串中查找匹配项,但无法正常工作。我想匹配function gcb_process.

这就是我所做的:

$gatewayname = basename($path, ".php");
$contents = file_get_contents($path);
$searchname = $gatewayname . "_process";

preg_match("/function\s*".$searchname."/i", $contents, $matches);

我总是收到警告:

警告:preg_match_all():编译失败:在偏移量 11 处没有可重复的内容

这是怎么做到的?

4

1 回答 1

0

测试:

$subject = "I want to match occurence of function gcb_process.";
$pattern = '/function gcb_process/';
preg_match($pattern, $subject, $matches);
print_r($matches);

输出:

Array ( [0] => function gcb_process )  

阅读PHP 文档更多细节

于 2013-08-11T03:45:39.587 回答