-1
stdClass Object
(
    [status] => success
    [message] => stdClass Object
        (
            [key] => stdClass Object
                (
                    [remoteJid] => 911334567890@c.us
                    [fromMe] => 1
                    [id] => BAE56CB55463AFE9
                )

            [message] => stdClass Object
                (
                    [documentMessage] => stdClass Object
                        (
                            [url] => some url
                            [mimetype] => application/pdf
                            [fileSha256] => hnB2OoCAoeO7lw6d6FFhankwG1UFHfnRCa+1mZisrfI=
                            [fileLength] => 4115
                            [mediaKey] => EfLEM03VY6ojspurx2b42H4ZQZh+8blcGZaa+mBiWhs=
                            [fileName] => To, abc.pdf
                            [fileEncSha256] => np/RpzMPZZVXzGJaMzu64R13vCAez4Pm10CTOK4+QmE=
                            [directPath] => /v/t62.711
                            [mediaKeyTimestamp] => 1686313196
                            [caption] => Thanks & Regards.
                        )

                )

            [messageTimestamp] => 1686313196
        )

)

Getting this output from curl which I have stored in $output.

I have tried: echo $output->status

shingo
  • 18,436
  • 5
  • 23
  • 42
  • Didn't print anything – Mihir Dhabalia Jun 10 '23 at 04:29
  • I can't reproduce this: https://3v4l.org/0Mo6Q, so please show the relative code. – shingo Jun 10 '23 at 04:58
  • I am having above object as my output from api....need to store only status to my database – Mihir Dhabalia Jun 10 '23 at 06:28
  • Is that the literal output you see when you `echo $output` or is it the formatted output you see when you `print_r($output)`? – rickdenhaan Jun 10 '23 at 10:34
  • I can see the output on echo $output – Mihir Dhabalia Jun 10 '23 at 15:09
  • Can you edit your question and add the code you have from where you execute `curl_exec` to where you define `$output = …`? The output in your question is definitely the result of `print_r`, if you’re seeing this when you `echo` I want to know if your code is doing that somewhere or if that is the raw output from curl – rickdenhaan Jun 11 '23 at 11:19
  • It sounds like the API endpoint you are fetching this _from_, might have simply given a `print_r($something);` as return value ...? That would not be a good idea, the purpose of print_r is to make formatted debug outputs, not to return data in any format that would be suitable for "transport" between systems. – CBroe Jun 12 '23 at 07:43

1 Answers1

0

To access the status field from $output variable you can use the following PHP code:

$data = json_decode($output); // Decode the JSON response into a PHP object

$status = $data->status; // Access the "status" field

echo $status; 
Manuvo
  • 748
  • 5
  • 15
shubhada
  • 1
  • 2