0

我这里的语法有这个问题,但我不知道它是什么..

你能帮帮我吗?它必须在网址中...我想我表达它的方式可能有任何错误,因为当我使用纯网址时它可以工作..

谢谢!

$url='http://testext.i-movo.com/api/receivesms.aspx?".$str_from.$str_zip.$phone.$str_time.$date1.$str_msg';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
return $output;
4

2 回答 2

1

代替

$url='http://testext.i-movo.com/api/receivesms.aspx?".$str_from.$str_zip.$phone.$str_time.$date1.$str_msg';

$url="http://testext.i-movo.com/api/receivesms.aspx?".$str_from.$str_zip.$phone.$str_time.$date1.$str_msg;


更新
我们实际上还需要查看分配给您的变量的值,并且可能是您正在使用的 API 的链接。URL 的参数可能需要看起来像

"from=" . $str_from . "&zip=" . $zip .. // etc
于 2012-09-14T22:06:13.423 回答
1

您不想将字符串连接放在引号内 - 而是在引号外进行。您将变量(查询参数)连接到字符串文字(URL)和字符串文字,而不是整个事物,由引号定义。因此,取出最后的单引号,并更改字符串文字周围的引号以使其匹配。

至于使用哪个引号,PHP 中单引号和双引号之间的区别(或其中一个区别,但可能是最相关的)是使用双引号,您可以将变量放在字符串中,它们将被替换为值,而使用单引号时,值的名称将按字面意思表示。所以如果 $name 是 "Andrew" 而你做到了

"My name is $name"

字符串将是My name is Andrew. 但是,如果你这样做了

'My name is $name'

变量名不会被其值替换,结果字符串将是My name is $name

在您的情况下,您有两个选择。第一种是使用字符串连接,你使用的引号无关紧要(这个例子也可以使用单引号):

"http://testext.i-movo.com/api/receivesms.aspx?" . $str_from . $str_zip . $phone . $str_time . $date1 . $str_msg

第二个是在字符串中使用变量替换,看起来像

"http://testext.i-movo.com/api/receivesms.aspx?$str_from$str_zip$phone$str_time$date1$str_msg"

另外,我在这里假设您的变量($str_from 除外)都具有&key=value. 在您的查询参数中(即问号后面指定您传递的选项的部分),您必须用 & 分隔键/值对,并且键和值本身必须按照我上面指定的方式编写。所以你会希望最终结果看起来像

http://testext.i-movo.com/api/receivesms.aspx?from=whatever&zip=27703&phone=5551234567&time=143295438&date=septemberfourteenth

于 2012-09-14T22:07:06.047 回答