【问题标题】:How to get and print values properly form a given URL parameter如何从给定的 URL 参数中正确获取和打印值
【发布时间】:2014-10-22 12:28:42
【问题描述】:

我有这个带参数的链接:

http://example.com/article?id=571&id=550&id=276

我希望获取所有的 id 值,形成一个数组并输出到一个字段,我尝试了几种方法但都没有奏效,有人可以帮忙吗?谢谢

  if (isset($_GET['id'])){

      // create an array to store all ids from the parameter

      // Output each values in the array to $string variable

      $form['submitted']['my_field']['#value'] = $string;  // output all ids via this field.

  }; //endif ;

我希望它会在场上这样输出:“571,550,276”

【问题讨论】:

  • 这不好。您需要使用 get 中的唯一键,并且您可以使用 $_GET 或使用带有分隔符的一个参数传递它。在你的情况下,$_GET['id'] 值将始终是 url 中的最后一个 ids 值。

标签: php arrays geturl


【解决方案1】:

您的所有参数都将被忽略,它们在您的网址中必须是唯一的
试试这个方法http://example.com/article?id=571, 550, 276

if(isset($_GET['id'])){
print $_GET['id'];
}

【讨论】:

    猜你喜欢
    • 2016-04-24
    • 2013-07-27
    • 2018-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多