将数据附加到GET参数


Append data to GET parameter

我只需要将数据发送到不同主机上的GET参数,但在PHP中找不到适合这种情况的函数。这是我唯一的问题。

例如,发送信息参数的任何值:

http://example.com/obtainer.php?information=

感谢:)

查询字符串(_GET)参数的构造如下;

www.example.com/index.php?param1=value&param2=value

如果您通过表单向信息参数发送任何值,请执行以下操作;

<form action="" method="get">
 <input type="text" name="information" value="" />
 <input type="submit" value="Send" />
</form>

然而,如果您通过链接发送数据,请手动写入,就像这样;

<a href="index.php?information=hello">Link</a>

请记住,在将字符串放入查询字符串时,请确保使用urlencode

我想你正在向http://example.com/obtainer.php发送一些东西,你可以尝试下面的PHP函数。。。

file_get_contents('http://example.com/obtainer.php?information='.urlencode('whatever');

这取决于你试图做什么。如果你试图为另一个网站使用API,那么你想要的是file_get_contents函数。例如:

<?php
$username = 'S1nus';
?>
<img src=<?php echo "'" . file_get_contents("http://psirup.com/api/getpsignature?user=$username") . "'";?>

将返回此图像(也许不是最好的示例,但却是我能想到的最简单的API)。(别忘了urlencode()这个参数,我差点忘了)。

但是,您可能希望使用HttpRequest::send。本文档解释了如何将其用于GET请求。