PHP短信问题。卡住了
我到处寻找这个问题的答案,却找不到。我正在尝试将Twilio支持的短信应答器集成到我的房地产网站中。到目前为止,我已经能够响应单个关键字并提供适当的响应 然而,使用这种方式需要应用程序通过sms文本字符串查找字符串中的任何关键字并做出适当的响应 例如,我可以让以下操作非常好地工作:输入单个关键字“listing”,然后它提供一个响应。但是,如果有人发短信说“你能告诉我任何一条街123号的名单吗?”回复者将无法回复 我需要一种方法让它在该字符串中找到“listing”(或任何其他关键字),并响应该关键字,而不是忽略整个内容 这就是我正在研究的内容(显然我的关键字会有所不同): 可在此处找到: 但它似乎不起作用,或者我不知道如何正确地实现它PHP短信问题。卡住了,php,arrays,twilio,Php,Arrays,Twilio,我到处寻找这个问题的答案,却找不到。我正在尝试将Twilio支持的短信应答器集成到我的房地产网站中。到目前为止,我已经能够响应单个关键字并提供适当的响应 然而,使用这种方式需要应用程序通过sms文本字符串查找字符串中的任何关键字并做出适当的响应 例如,我可以让以下操作非常好地工作:输入单个关键字“listing”,然后它提供一个响应。但是,如果有人发短信说“你能告诉我任何一条街123号的名单吗?”回复者将无法回复 我需要一种方法让它在该字符串中找到“listing”(或任何其他关键字),并响应该
FWIW,我不是一个程序员,但对这方面的理解有限。我只是想建立自己的工具,因为开箱即用的解决方案不适合我。感谢您的帮助,并随时提出您需要的任何问题。尝试通过
urlencode
传递消息。您是如何尝试实施stripos
建议的?对我来说,这似乎是正确的方法。另外,当你为自己构建类似的东西时,我非常高兴地称你为程序员。我觉得那太棒了。谢谢!我正在研究strpos,因为我也认为这是一个方向。我想你可以说我是一名兼职程序员,而不是lol。试着通过urlencode
传递消息。你是如何尝试实现stripos
建议的?对我来说,这似乎是正确的方法。另外,当你为自己构建类似的东西时,我非常高兴地称你为程序员。我觉得那太棒了。谢谢!我正在研究strpos,因为我也认为这是一个方向。我想你可以说我是一个兼职程序员,而不是lol。
<?php
/* Include twilio-php, the official Twilio PHP Helper Library,
* which can be found at
* http://www.twilio.com/docs/libraries
*/
include('Services/Twilio.php');
/* Controller: Match the keyword with the customized SMS reply. */
function index(){
$response = new Services_Twilio_Twiml();
$response->sms("Reply with one of the following keywords:
monkey, dog, pigeon, owl.");
echo $response;
}
function monkey(){
$response = new Services_Twilio_Twiml();
$response->sms("Monkey. A small to medium-sized primate that
typically has a long tail, most kinds of which live in trees in
tropical countries.");
echo $response;
}
function dog(){
$response = new Services_Twilio_Twiml();
$response->sms("Dog. A domesticated carnivorous mammal that
typically has a long snout, an acute sense of smell, and a barking,
howling, or whining voice.");
echo $response;
}
function pigeon(){
$response = new Services_Twilio_Twiml();
$response->sms("Pigeon. A stout seed- or fruit-eating bird with
a small head, short legs, and a cooing voice, typically having gray and
white plumage.");
echo $response;
}
function owl(){
$response = new Services_Twilio_Twiml();
$response->sms("Owl. A nocturnal bird of prey with large
forward-facing eyes surrounded by facial disks, a hooked beak,
and typically a loud call.");
echo $response;
}
/* Read the contents of the 'Body' field of the Request. */
$body = $_REQUEST['Body'];
/* Remove formatting from $body until it is just lowercase
characters without punctuation or spaces. */
$result = preg_replace("/[^A-Za-z0-9]/u", " ", $body);
$result = trim($result);
$result = strtolower($result);
/* Router: Match the ‘Body’ field with index of keywords */
switch ($result) {
case 'monkey':
monkey();
break;
case 'dog':
dog();
break;
case 'pigeon':
pigeon();
break;
case 'owl':
owl();
break;
/* Optional: Add new routing logic above this line. */
default:
index();
}
/* Read the contents of the 'Body' field of the Request. */
$body = $_REQUEST['Body'];
// Check to see if contains the word "logging"
if(stripos($body, "logging") !== FALSE) {
// message contains the word "logging"
} else {
// message does not contain the word "logging"
}