I've nearly figured out my sms issue, and have it narrowed down to one small issue that I can't seem to get to work.
Here's what I have:
include('Services/Twilio.php');
/* 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 = rtrim($body);
$result = strtolower($result);
$text = explode(' ',$result);
$keyword = array('dog','pigeon','owl');
$word = array_intersect($keyword,$text);
$key = array_search($word, array_keys($keyword));
$word[$key]();
/* ^^this is the issue */
So the SMS app now can read a sentence and find the keyword no sweat. Problem is, I also need to have the position of the word in relation to where it is in the keyword array. If I manually change the number to the correct position and send a text containing that keyword it functions flawlessly.
Unfortunately array_search
doesn't work because it can't accept a dynamic needle. Is there any way to have the array position auto populate based on what keyword is found? In my code above, you can see (hopefully) what I'm trying to do.