preg_match不匹配

I'l*_*ack 1 php regex preg-match

我试图从transaction(123456)HTML中获取ID

它似乎没有返回任何东西.

 $response = "</body> </html><script type='text/javascript'>transaction(123456);</script>";

 preg_match('/^transaction\((\d+)\)/', $response, $match);

 print_r($match);

if (is_numeric($match[1])) {
  echo "Your ID: " . $match[1];
}
Run Code Online (Sandbox Code Playgroud)

nic*_*ckb 5

因为你有字符串锚的开头^,并且transaction(不在字符串的开头.删除(或添加非贪婪的匹配),它将工作(如此演示所示):

preg_match('/transaction\((\d+)\)/', $response, $match);
Run Code Online (Sandbox Code Playgroud)