如何通过file_get_contents传递URL中的变量值

时间:2014-03-19 16:14:03

标签: php file-get-contents

我想将SMS集成到我的API并尝试在URL中传递变量,但它表示错误,没有找到数字。

请帮忙

$sender = "9999708993";
$reply_message = "This is an auto generated message";

echo $sender;
echo $reply_message;

$lines = file_get_contents('http://sms2.oxyzen.in/httpapi/sendsms.php?loginid=myid&password=mypassword&senderid=mysenderid&message=$reply_message&number=$sender');

echo "<pre>$lines</pre>"; 

2 个答案:

答案 0 :(得分:4)

如果要将变量放入:

,请使用双引号而不是单引号
$lines = file_get_contents("http://sms2.oxyzen.in/httpapi/sendsms.php?loginid=myid&password=mypassword&senderid=mysenderid&message=$reply_message&number=$sender");

请试试这个:

$sender = "9999708993";
$reply_message = urlencode("This is an auto generated message");


//I think you need to change these
$loginid='myid';
$mypassword='mypassword';
$mysenderid='mysenderid'; 

$uri = "http://sms2.oxyzen.in/httpapi/sendsms.php?loginid=$myid&password=$mypassword&senderid=$mysenderid&message=$reply_message&number=$sender";
var_dump($uri);
$lines=file_get_contents($uri);
var_dump($lines);

答案 1 :(得分:0)

尝试清除该URL,它的结尾可能会有一个新行 trim(“ $ URL”);

相关问题