在 URL 中传递字符串和 int


Passing string and int in URL

我认为这不是一个非常典型的问题,但我被困在这里。我必须在URL中传递一个字符串和一个整数,以便我的PHP处理它。

我正在构建这样的链接... $link = 'index.php?NAME=' . $name . '&id=' . $id;

但是当它出现在 URL 中时,它会更改为 index.php?NAME=hello&id=10

现在 id 无法被 GET 识别。

对所有

变量使用 url_encode()。 或者,更好的是,使用 http_build_query() .

$link = 'index.php?' . http_build_query(array(
    'NAME' => $name,
    'id' => $id
));
  • http://php.net/manual/en/function.urlencode.php
  • http://php.net/manual/en/function.http-build-query.php

<a href="http://www.somedomain.com/<?php echo $link;?>">Link</a>应该可以工作,你能详细说明你是如何显示链接的吗?

尝试这个简单的解决方案;

$link = 'index.php?NAME="{$name}&id={$id}"';