如何在PHP中获取URL参数?

时间:2020-12-24 10:28:58

http://{{base_url}}/post/857161551776694272

I want to get the post_id(which is bold) in the above URL. Parameter does not contain any param name. (Its a PATCH method which also has a json body)

我想在上面的URL中获取post_id(粗体)。参数不包含任何参数名称。 (它的PATCH方法也有一个json体)

1 个解决方案

#1


0  

you can get your url segments with parse_url e.g :

您可以使用parse_url获取您的网址片段,例如:

$uri_path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$uri_segments = explode('/', $uri_path);

echo $uri_segments[0];
echo "<br>";
echo $uri_segments[1];

#1


0  

you can get your url segments with parse_url e.g :

您可以使用parse_url获取您的网址片段,例如:

$uri_path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$uri_segments = explode('/', $uri_path);

echo $uri_segments[0];
echo "<br>";
echo $uri_segments[1];