【问题标题】: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
    

    【讨论】:

      猜你喜欢
      • 2010-11-19
      • 2012-05-17
      • 2011-01-15
      • 2014-10-14
      • 1970-01-01
      • 2014-11-21
      • 2010-10-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多