Search code examples
phpsmsmessagesms-gateway

How do I read / get contents of a text message body?


I'm going to use a SMS to Web Server, which will forward incoming text messages to my web server.

The message body will contain some short codes, a mobile number and a amount in a format. I need to store the details separately to variables.

Here's an example, what I will receive in my web server through POST method:

$sender = "9999912345";
$date = "2017-04-14 13:04:40";
$message = "RCG ARTL 9700012345 50";

I need to store the contents of $message separately to variables:

$cmd = "RCG";
$op = "ARTL";
$no = "9700012345";
$amt = "50";

Please help!


Solution

  • <?php
        $message = "RCG ARTL 9700012345 50";
        list($cmd, $op, $no, $amt) = explode(" ",$message);
    

    you can test it.