2010-12-01 71 views
0

尊敬的各位,
我如何使用php file_get_content函数发送参数。使用php发送参数file_get_content函数

$id='123'; 
$name='blah'; 
$response=file_get_contents('http://localhost/abc/abc.php?id=$id&name=$name'); 
echo $response; 

我需要发送的$ id和name值abc.php page.Here传递值不工作。还我清洁香港?ID = “$ ID” & NAME = “$名”价值。它也没有工作。但工作 .say-

$response=file_get_contents('http://localhost/abc/abc.php?id=123&name=blah'); 

现在straite参数是他们的任何一种心脏谁可以帮我送了2个参数的$ id和$名abc.php?

谢谢
里亚德

+0

谢谢all..all解决方案.. – riad 2010-12-01 07:05:39

回答

4

单引号禁止变量代换。

$response=file_get_contents("http://localhost/abc/abc.php?id=$id&name=$name"); 

不要忘了对所有参数进行URL编码。

+1

urlencode($ message)为我做了这份工作,谢谢! – ecairol 2013-09-20 21:23:56

1

使用双引号而不是单引号。即"http://localhost/abc/abc.php?id=$id&name=$name"

2

如果要启用变量替换字符串中,你必须使用双引号:

$response=file_get_contents("http://localhost/abc/abc.php?id=$id&name=$name"); 
1

尝试

$response = file_get_contents(sprintf("http://localhost/abc/abc.php?id=%s&name=%s", $id, $name)); 
0

把这个东西在双引号:

$response=file_get_contents("http://localhost/abc/abc.php?id=$id&name=$name"); 

谢谢。