首页 > 解决方案 > 无法使用 twilio 接收传入的短信正文单个字

问题描述

我在我的网站上使用 Twilio PHP API 发送和接收短信。我成功发送短信,但我无法接收来自传入短信的单个单词。假设客户在我的 twilio 号码中发送了一条短信,例如 =“我要回家了“现在我想从那行中取出两个词,例如 i,home。我可以用这个代码吗

<?php
    $msg1 = $_REQUEST['Body[0]'];
    $msg2 = $_REQUEST['Body[2]'];
header('Content-Type: text/xml');
?>

我对吗?或者我应该改变什么

标签: codeignitertwiliotwilio-apitwilio-phptwilio-programmable-chat

解决方案


Twilio developer evangelist here.

The issue here is that you have the square brackets inside the string. Try this instead:

<?php
    $body = $_REQUEST['Body'];
    $msg1 = $body[0];
    $msg2 = $body[2];
header('Content-Type: text/xml');
?>

推荐阅读