[实践OK]preg_match_all的用法复习,完全可以用来测试Nginx的urlrewrite正则是否写正确以确认其重写的变量$1,$2其顺序是否对上重写规则了。
参看N久前写的一篇文章:http://blog.5ifd.com/post/1253/
朋友要匹配:123.html
code:
result:
Array
(
[0] => Array
(
[0] => http://www.test.com/123.html
)
[1] => Array
(
[0] => 123
)
)
取得$str_out的$str_out[1][0]即可!
第一示例:
可以用来简化Nginx的$1,$2。
rewrite "^/(\d*)/trends-list-(\w*)\.html$" /index.php?d=front&c=index&a=trends&uid=$1&page=$2&tag=list&max_age=1800 last;
---------- 调试PHP ----------
Array
(
[0] => 12204886/trends-list-4
[1] => 12204886
[2] => 4
)
第二示例:
rewrite "^/(\d*)/friend-(myfans|myfollow)-(\w*)\.html$" /index.php?d=front&c=index&a=friend&uid=$1&tag=$2&page=$3&max_age=1800 last;
---------- 调试PHP ----------
Array
(
[0] => /30991799/friend-myfollow-5.html
[1] => 30991799
[2] => myfollow
[3] => 5
)
第三示例:
rewrite "^/list-(\d*)-(\d*)-(\d*)-(.*)\.html$" /index.php?d=site&c=list&a=index&type=$1&label=$2&period=$3&name=$4 last;
---------- 调试PHP ----------
Array
(
[0] => /list-0-0-1-测试.html
[1] => 0
[2] => 0
[3] => 1
[4] => 测试
)
______________________________________________________________
接合Nginx的urlrewrite进行$1,$2类似配置的方法:
通过print_r打印数组是不错的调试nginx重写的适用方法:
index2.php代码如下:
http://jackxiang.com/12204886/trends-list-4.html
Array
(
[d] => front
[c] => index
[a] => trends
[uid] => 12204886
[page] => 4
[tag] => list
[max_age] => 1800
)
http://jackxiang.com/30991799/friend-myfollow-5.html
Array
(
[d] => front
[c] => index
[a] => friend
[uid] => 30991799
[tag] => myfollow
[page] => 5
[max_age] => 1800
)
朋友要匹配:123.html
code:
result:
Array
(
[0] => Array
(
[0] => http://www.test.com/123.html
)
[1] => Array
(
[0] => 123
)
)
取得$str_out的$str_out[1][0]即可!
第一示例:
可以用来简化Nginx的$1,$2。
rewrite "^/(\d*)/trends-list-(\w*)\.html$" /index.php?d=front&c=index&a=trends&uid=$1&page=$2&tag=list&max_age=1800 last;
---------- 调试PHP ----------
Array
(
[0] => 12204886/trends-list-4
[1] => 12204886
[2] => 4
)
第二示例:
rewrite "^/(\d*)/friend-(myfans|myfollow)-(\w*)\.html$" /index.php?d=front&c=index&a=friend&uid=$1&tag=$2&page=$3&max_age=1800 last;
---------- 调试PHP ----------
Array
(
[0] => /30991799/friend-myfollow-5.html
[1] => 30991799
[2] => myfollow
[3] => 5
)
第三示例:
rewrite "^/list-(\d*)-(\d*)-(\d*)-(.*)\.html$" /index.php?d=site&c=list&a=index&type=$1&label=$2&period=$3&name=$4 last;
---------- 调试PHP ----------
Array
(
[0] => /list-0-0-1-测试.html
[1] => 0
[2] => 0
[3] => 1
[4] => 测试
)
______________________________________________________________
接合Nginx的urlrewrite进行$1,$2类似配置的方法:
通过print_r打印数组是不错的调试nginx重写的适用方法:
index2.php代码如下:
http://jackxiang.com/12204886/trends-list-4.html
Array
(
[d] => front
[c] => index
[a] => trends
[uid] => 12204886
[page] => 4
[tag] => list
[max_age] => 1800
)
http://jackxiang.com/30991799/friend-myfollow-5.html
Array
(
[d] => front
[c] => index
[a] => friend
[uid] => 30991799
[tag] => myfollow
[page] => 5
[max_age] => 1800
)
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:https://jackxiang.com/post/1950/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
最后编辑: jackxiang 编辑于2014-7-25 10:51
评论列表