我正在使用twilio发送短信。如果我直接插入我的号码8881231234
,它就会起作用。以下代码有效:
$client = new Services_Twilio($sid, $token);
$message = $client->account->messages->sendMessage(
'9991231234', // From a valid Twilio number
'8881231234', // Text this number
"Hello monkey!" //insert message here
);
print $message->sid;
但是当我通过从数据库添加记录替换它不会工作。如下所示它不会起作用:
echo $row2["handset"]; // I can see my number
$client = new Services_Twilio($sid, $token);
$message = $client->account->messages->sendMessage(
'9991231234', // From a valid Twilio number
'$row2["handset"]', // Text this number
"Hello monkey!"
);
print $message->sid;
我回复$row2["handset"]
,我的数字8881231234
正确显示。这也行不通:
$handset = '8881231234';
$client = new Services_Twilio($sid, $token);
$message = $client->account->messages->sendMessage(
'9991231234', // From a valid Twilio number
'$handset', // Text this number
"Hello monkey!" // insert message here
);
print $message->sid;
为什么?请帮帮我。
答案 0 :(得分:2)
如果您希望将变量解释为变量,请使用双引号:
$var = "$var2";
$var = '$var2';
不起作用。
它也适用于数组:
$var = "$var2['whatever']";
或者干脆做:
$var = $var2['whatever'];
连接:
$var = $var2['whatever']."suffix";
在你的情况下你只想做:
$message = $client->account->messages->sendMessage(
'9991231234', // From a valid Twilio number
$row2["handset"], // Text this number
"Hello monkey!"
);