PHP 生成的正则,以 #
开头 #u
结尾的,为什么里面的 /
反斜杠不用转义成 \/
<code>php</code><code><?php $pattern = '#^info/(?P<type>(area|cat))-(?P<v1>\d+)-(?P<v2>\d+)-(?P<v3>\d+)/(?P<page>\d+)/$#u'; $str = 'info/area-19-0-0/40/'; preg_match($pattern,$str,$matches); print_r($matches); </page></v3></v2></v1></code>
<code>Array ( [0] => info/area-19-0-0/40/ [type] => area [1] => area [2] => area [v1] => 19 [3] => 19 [v2] => 0 [4] => 0 [v3] => 0 [5] => 0 [page] => 40 [6] => 40 ) </code>
PHP 生成的正则,以 #
开头 #u
结尾的,为什么里面的 /
反斜杠不用转义成 \/
<code>php</code><code><?php $pattern = '#^info/(?P<type>(area|cat))-(?P<v1>\d+)-(?P<v2>\d+)-(?P<v3>\d+)/(?P<page>\d+)/$#u'; $str = 'info/area-19-0-0/40/'; preg_match($pattern,$str,$matches); print_r($matches); </page></v3></v2></v1></code>
<code>Array ( [0] => info/area-19-0-0/40/ [type] => area [1] => area [2] => area [v1] => 19 [3] => 19 [v2] => 0 [4] => 0 [v3] => 0 [5] => 0 [page] => 40 [6] => 40 ) </code>
因为它的正则分隔符是 #
号, 所以 /
不需要进行转义.