简体   繁体   中英

String matching with regular expression

I'm trying to find match in string with regular expression but is not working. I want to match occurence of function gcb_process .

This is what I did:

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

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

I always get a warning:

Warning: preg_match_all(): Compilation failed: nothing to repeat at offset 11

How is this done?

Tested:

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

Output:

Array ( [0] => function gcb_process )  

Read PHP Doc more details

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM