0

i try to use some sms api and i have to get message-id. First of all here is the my api code.

$url = 'https://rest.nexmo.com/sms/json?' . http_build_query(
    [
      'api_key' =>  'xxx',
      'api_secret' => 'xxx',
      'to' => 'xxx',
      'from' => 'xxx',
      'text' => 'xxx'
    ]
);
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $response = curl_exec($ch);

When i use this code it's working for sending sms and return response. And here is the json response.

{ "message-count": "1", "messages": [{ "to": "905075214049", "message-id": "0C000000440A086C", "status": "0", "remaining-balance": "1.52250000", "message-price": "0.01910000", "network": "28603" }] }

And i use the print_r function to see the structrue of json data. And here it's.

stdClass Object
(
    [message-count] => 1
    [messages] => Array
        (
            [0] => stdClass Object
                (
                    [to] => xxx
                    [message-id] => 0C000000440A086C
                    [status] => 0
                    [remaining-balance] => 1.52250000
                    [message-price] => 0.01910000
                    [network] => 28603
                )

        )

)

I use this code to get "message-id" into my php value.

$json_decode = json_decode($response);
$sonuc->messages[0]->message-id;

My issue is; if i try to get network section from this json it works. But if i try to get "message-id" section it returns only 0 on the screen. I really don't know how can i get full message-id. Please help.

2 Answers 2

3

- char is not allowed for using as property or variable name. If you want get this property, do it like this:

$sonuc->messages[0]->{"message-id"}
Sign up to request clarification or add additional context in comments.

Comments

0

You are using the wrong variable name. Try using

$sonuc = json_decode($response);
echo $sonuc->messages[0]->message-id;

1 Comment

thanks for that. this is my mistake. but the result still same. I get 0 on the screen when i try to get message-id.

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.