【问题标题】:How to get the URL parameter in PHP?如何在 PHP 中获取 URL 参数?
【发布时间】:2017-09-30 20:29:06
【问题描述】:

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

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

【问题讨论】:

  • 你的.htaccess是什么?
  • 您可以使用 codeignitor 框架来实现这一点。这很简单。
  • 谢谢!它有帮助!!!!

标签: php http url http-method


【解决方案1】:

您可以使用 parse_url 获取您的 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];

【讨论】:

  • 它的工作,但不是一个很有前途的方式。应该有一个标准的方法来做到这一点。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-01
相关资源
最近更新 更多