获取上次URL段
如果要获取上次URI段,请在PHP中使用array_pop()函数。
$lastUriSegment = array_pop($uriSegments); echo $lastUriSegment; //returns bar
URL段用于Web应用程序中的许多目的。
我们可以在PHP中轻松解析URL段。
其中我们将提供使用PHP获取URI段和最后一个URL段的示例代码。
获取PHP中的URI段
使用以下代码获取当前URL的URL段。
它将当前URL的所有段返回为数组。
$uriSegments = explode("/", parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
用法:
当当前的URL是'http://www.example.com/codex/foo/bar'时。
echo $uriSegments[1]; //returns codex echo $uriSegments[2]; //returns foo echo $uriSegments[3]; //returns bar
日期:2020-06-02 22:15:45 来源:oir作者:oir