0
$string='this dog is done';
preg_match('/^this dog is [^.]+/',$string,$m);
echo $m[0]."\n"; // prints "this dog is done"
我该怎么做'完成',没有剩下的字符串?如何返回匹配的部分?
$string='this dog is done';
preg_match('/^this dog is [^.]+/',$string,$m);
echo $m[0]."\n"; // prints "this dog is done"
我该怎么做'完成',没有剩下的字符串?如何返回匹配的部分?
如果提供的比赛,则充满了搜索的结果。
$matches[0]
将包含匹配完整模式的文本,$matches[1]
将具有匹配第一个捕获的括号内子模式的文本,依此类推。
所以:
$string='this dog is done';
preg_match('/^this dog is ([^.]+)/',$string,$m);
echo $m[1]."\n";