arrays - PHP SMS issue. Stuck -


i have searched high , low answer this, , cannot find it. trying trying integrate twilio powered sms responder real estate site. far have able respond single keywords , provide appropriate response.

however, way used require app through sms text string find keyword(s) in string , respond appropriately.

for example, can following work fine: single keyword 'listing' texted in, , provides response. but, if texts 'what can tell me listing @ 123 street?' responder not able respond.

i need way have find 'listing' (or other keyword) in string , respond keyword rather ignore whole thing.

this i'm working off of (obviously keywords different):

<?php  /* include twilio-php, official twilio php helper library,  * can found @  * http://www.twilio.com/docs/libraries */  include('services/twilio.php');  /* controller: match keyword customized sms reply. */ function index(){     $response = new services_twilio_twiml();     $response->sms("reply 1 of following keywords: monkey, dog, pigeon, owl.");     echo $response; }  function monkey(){     $response = new services_twilio_twiml();     $response->sms("monkey. small medium-sized primate typically has long tail, kinds of live in trees in tropical countries.");     echo $response; }  function dog(){     $response = new services_twilio_twiml();     $response->sms("dog. domesticated carnivorous mammal  typically has long snout, acute sense of smell, , barking, howling, or whining voice.");     echo $response; }  function pigeon(){     $response = new services_twilio_twiml();     $response->sms("pigeon. stout seed- or fruit-eating bird small head, short legs, , cooing voice, typically having gray , white plumage.");     echo $response; }  function owl(){     $response = new services_twilio_twiml();     $response->sms("owl. nocturnal bird of prey large forward-facing eyes surrounded facial disks, hooked beak, , typically loud call.");     echo $response; }  /* read contents of 'body' field of request. */ $body = $_request['body'];  /* remove formatting $body until lowercase characters without punctuation or spaces. */ $result = preg_replace("/[^a-za-z0-9]/u", " ", $body); $result = trim($result); $result = strtolower($result);  /* router: match ‘body’ field 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 line. */     default:         index(); } 

found here: https://www.twilio.com/help/faq/sms/how-do-i-build-a-sms-keyword-response-application

i found this:

/* read contents of 'body' field of request. */ $body = $_request['body']; // check see if contains word "logging" if(stripos($body, "logging") !== false) {   // message contains word "logging" } else {   // message not contain word "logging" } 

found here:twilio sms keyword autoresponder search incoming body

but doesn't seem work, or can't figure out how implement it.

fwiw, not programmer, have limited understanding of this. i'm trying build own tools because out of box solutions don't work me. help, , feel free ask questions need to.


Comments