【问题标题】:Line break Twilio API PHP换行 Twilio API PHP
【发布时间】:2018-07-02 15:07:53
【问题描述】:

我在带有本地库的 php 中使用 Twilio api,我从 stackoverflow 或他们的官方网站尝试了许多解决方案,但没有一个有效。请在将其标记为已回答之前考虑一下。我正在提供一些证明它确实不起作用的证据。如果我缺少一些标题等,请帮忙,因为我尝试了官方解决方案但它不起作用。

$sid="xxxxxxxxxxx";
$token="xyxxxcxc";
    $client=new Client($sid, $token);

     function Send_Message($client, $msg, $to){

      return $client->messages->create(

        $to,

        array('from' => '+12566661887',

          'body'=>$msg

       )

      );

    }

Please check this image all possible solution

【问题讨论】:

  • 请告诉我们$msg 的设置位置。

标签: php sms twilio


【解决方案1】:

单引号禁止十六进制代码替换和转义序列,如 \r 或 \n,将按字面输出。

(http://php.net/manual/en/language.types.string.php#language.types.string.syntax.single)

这行不通

array(
    'from' => $twilio_number,
    'body' => 'I sent \r\n this message in under 10 minutes!'
)

改为使用双引号,应该可以

array(
    'from' => $twilio_number,
    'body' => "I sent \r\n this message in under 10 minutes!"
)

$msg

$msg = "I sent \r\n this message in under 10 minutes!";


array(
    'from' => $twilio_number,
    'body' => $msg
)

【讨论】:

  • 可能是这个,但我们不知道 $msg 有来自 OP 发布的单引号 \n 标记。
  • 非常感谢。我使用的是单引号。感谢您的帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多