【问题标题】:How to get the variable values from the current page url in php [duplicate]如何从php中的当前页面url获取变量值[重复]
【发布时间】:2019-03-25 12:12:24
【问题描述】:
假设网址是https://www.example.com/page.php?id=1&title=this+is+a+sample+content。
现在我的问题是在这里检索 id 和 title 的值
【问题讨论】:
标签:
php
http
url
query-string
【解决方案1】:
您可以在 PHP 中使用$_GET 获取 URL 参数。你也可以看看$_GET documentation。
在你的情况下是:
<?php
echo $_GET["title"];
或者带有if 语句的更好的变体。
<?php
if(isset($_GET["title"])) {
echo htmlspecialchars($_GET["title"]);
};
【解决方案2】:
如果你在同一页page.php,那么你可以得到这样的变量:
<?php
$id = $_GET['id'];
$title = $_GET['title'];
?>
所以,这将输出是
id = 1
title = this is a sample content