A
A
andrey_levushkin2019-02-12 22:40:13
PHP
andrey_levushkin, 2019-02-12 22:40:13

How to extract the desired value?

When the bot receives a photo in a message, it returns the following query result:

{"type":"message_new","object":{"id":21,"date":1549999669,"out":0,"user_id":XXX,"read_state":0,"title":"","body":"","attachments":[{"type":"photo","photo":{"id":XXX,"album_id":-3,"owner_id":XXX,"photo_75":"https:\/\/pp.userapi.com\/c847124\/v847124220\/19df30\/BRfTwvsNzIY.jpg","photo_130":"https:\/\/pp.userapi.com\/c847124\/v847124220\/19df31\/LKbwyjwb1Ag.jpg","photo_604":"https:\/\/pp.userapi.com\/c847124\/v847124220\/19df32\/IUsQgkOm1zM.jpg","photo_807":"https:\/\/pp.userapi.com\/c847124\/v847124220\/19df33\/LHknGn3O8_s.jpg","photo_1280":"https:\/\/pp.userapi.com\/c847124\/v847124220\/19df34\/Z19Mgr2bifI.jpg","width":647,"height":960,"text":"","date":1549999667,"access_key":"ddcefea2de81b39bd4"}}]},"group_id":XXX}

To pull information about the sender of a message, I do this:
$user_id = $data->object->user_id;
But how can I pull out a link to a photo (photo_75)? It turns out there goes in an array ... which is also in an array like ...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Arthur, 2019-02-13
@arturka_v_10

$data->object->attachments;
run attachments in a loop and watch
because it will not always return the photo field with 0

D
Dmitry, 2019-02-12
@Compolomus

If json is not convenient, convert to an array
Curly braces object, square array

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question