与正则表达式匹配的字符串

时间:2013-08-11 03:35:21

标签: php regex

我正在尝试使用正则表达式查找字符串中的匹配但不起作用。 我希望匹配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处重复

这是怎么做到的?

1 个答案:

答案 0 :(得分: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 Doc更多详情

相关问题