在PHP中获取URL的一部分 [英] Get parts of URL in PHP

查看:70
本文介绍了在PHP中获取URL的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道使用PHP从URL提取参数"的最佳方法是什么.

I am just wondering what the best way of extracting "parameters" from an URL would be, using PHP.

如果我获得了网址:

http://example.com/user/100

如何使用PHP获取用户ID(100)?

How can I get the user id (100) using PHP?

推荐答案

要彻底,您需要从

这将为您提供带有少量键的阵列.您要寻找的是path.

That will give you an array with a handful of keys. The one you are looking for is path.

/上分割路径并采用最后一个.

Split the path on / and take the last one.

$path_parts=explode('/', $parts['path']);

您的ID现在在$path_parts[count($path_parts)-1]中.

这篇关于在PHP中获取URL的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆