3

Hello so I am using the callback feature of https://smsgateway.me and my current code is here:

<?php
include "smsGateway.php";
$smsGateway = new SmsGateway('[email protected]', 'password');

$message = //extract number value from multidimensional array;

$number = "09058789624";
$deviceID = 5495;
$result = $smsGateway->sendMessageToNumber($number, $message, $deviceID);
?>

In the documentation of smsgateway.me here I've used every http POST request and as you can see the parameter contact there says that it's a multidimensional array that contains the ID, Name and Number. Now what I wanted to do is to only get the Number. How can I do that?

5
  • The response is in JSON. Commented May 23, 2015 at 4:11
  • How to do that? If I am getting the message I just use $_POST['message'] Commented May 23, 2015 at 4:13
  • 1
    use var_dump() function to do that, put the $_POST['message'] in that var_dump() as var_dump($_POST['message']) Commented May 23, 2015 at 4:14
  • yes look at my edited comment Commented May 23, 2015 at 4:15
  • Call me Sourabh that is fine, no need to call me sir :) Commented May 23, 2015 at 4:18

2 Answers 2

3

Since the response is in JSON, you would do something like the following:

$json = json_decode($result);
echo $json->result->success->contact->number;

Of course you should also add error handling, and check to see the object exists, etc.

For reference, I used the documentation outlining the response that is returned when sending a message as specified here: Send Message to Number

The response format (for success):

{
   "success":true,
   "result":{
      "success":[
         {
            "id":"308",
            "device_id":"4",
            "message":"hello world!",
            "status":"pending",
            "send_at":"1414624856",
            "queued_at":"0",
            "sent_at":"0",
            "delivered_at":"0",
            "expires_at":"1414634856",
            "canceled_at":"0",
            "failed_at":"0",
            "received_at":"0",
            "error":"None",
            "created_at":"1414624856",
            "contact":{
               "id":"14",
               "name":"Phyllis Turner",
               "number":"+447791064713"
            }
         }
      ],
      "fails":[

      ]
   }
}
Sign up to request clarification or add additional context in comments.

Comments

2

First get the response data and print it, see it's array structure using:

echo "<pre>";
print_r($data);
echo "</pre>";

Based on that, access the data you want.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.