从url中获取号码的最简单方法是什么? [英] what is the easiest way of getting a number from a url?
本文介绍了从url中获取号码的最简单方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望有人能帮助我,我已经创建了这样的url
/this/is/a/test/index.asp
/this/is/a/test/index-1.asp
/this/is/a/test/index-2.asp
/this/is/a/test/index-3.asp
从URL中剥离数字的最简单方法是什么?
不使用这样的变量:
/this/is/a/test/index.asp?no=1
/this/is/a/test/index.asp?no=2
/this/is/a/test/index.asp?no=3
为了创建变量,我使用URL中的数字动态调用页面上的内容。
如果url是:/this/is/a/test/index-3.asp
,它应该使用3并根据它匹配内容,类似于我调用
?no=3
我正在使用PHP进行此操作.
url结构将始终将变量定义为匹配最后一个‘-’[the-number]‘.asp’
谢谢
Gerald Ferreira
推荐答案
您应该能够使用以下命令进行匹配:
if (preg_match('/-(d+).asp$/', $_SERVER['REQUEST_URI'], $a)) {
$pageNumber = $a[1];
} else {
// failed to match number from URL
}
这篇关于从url中获取号码的最简单方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文