首页 > 解决方案 > 在 Twilio Body 中发送多个 php 字符串

问题描述

朋友们,我正在尝试从帖子中传递一些字符串,例如 $name $phonenumber 等

$client = new Client($account_sid, $auth_token);
$client->messages->create(
// Where to send a text message (your cell phone?)
'+16477458535',
array(
'from' => $twilio_number,
'body' => $message
)

但似乎不能像这样连接:

'body' => $message, $name, phone

ETC... ???

有什么建议么?

标签: twilio

解决方案


Twilio 开发人员布道者在这里。

有几种方法可以用这样的多个变量构建字符串。

您可以使用直接连接字符串.运算符,例如:

'body' => $message . $name . $phone

虽然这会将所有字符串推到一起,所以如果$message是“hello”、$name是“Phil”和$phone是“+012345”,它会输出为“helloPhil+012345”。您可以在连接中添加空格来克服它:

'body' => $message . " " . $name . " " . $phone

或者,您可以将变量插入到 string中,如下所示:

'body' => "${message} ${name} ${phone}"

推荐阅读