Tuesday, July 12, 2022

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

Issue

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.



Answered By - nprog
Answer Checked By - Clifford M. (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.