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); </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); </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怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号