[英]String matching with regular expression
我正在嘗試使用正則表達式在字符串中找到匹配項,但無法正常工作。 我想匹配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處無法重復
怎么做?
經過測試:
$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更多詳細信息
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.