示例1:
$regex='#^/type/(\w+)/id/([0-9]+)$#i';
$str='/type/topic/id/11';
if(preg_match($regex,$str,$matches)){
var_export($matches);
}
result:
array (
0 => '/type/topic/id/11',
1 => 'topic',
2 => '11',
)
示例2:
$regex='#^/type/(?<type>\w+)/id/(?<id>[0-9]+)$#i';
$str='/type/topic/id/11';
if(preg_match($regex,$str,$matches)){
var_export($matches);
}
result:
array (
0 => '/type/topic/id/11',
'type' => 'topic',
1 => 'topic',
'id' => '11',
2 => '11', ) )