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";