fork download
  1. <?PHP
  2.  
  3.  
  4. $myJson = <<<JSON
  5. {"response":[{"id":14867,"from_id":-65923388,"to_id":-65923388,"date":1456947602,"post_type":"post","text":"Горячие клавиши Windows 10","attachment":{"type":"photo","photo":{"pid":404384423,"aid":223686536,"owner_id":-65923388,"user_id":100,"src":"http:\/\/cs7004.vk.me\/v7004692\/1af44\/5zhYes1I7xg.jpg","src_big":"http:\/\/cs7004.vk.me\/v7004692\/1af45\/QRt-0dPZ8qg.jpg","src_small":"http:\/\/cs7004.vk.me\/v7004692\/1af43\/msvfzwgm5tc.jpg","width":604,"height":302,"text":"Наука<br>http:\/\/vk.com\/public65923388","created":1456235510,"access_key":"d1cff88abc28e29b28"}},"attachments":[{"type":"photo","photo":{"pid":404384423,"aid":223686536,"owner_id":-65923388,"user_id":100,"src":"http:\/\/cs7004.vk.me\/v7004692\/1af44\/5zhYes1I7xg.jpg","src_big":"http:\/\/cs7004.vk.me\/v7004692\/1af45\/QRt-0dPZ8qg.jpg","src_small":"http:\/\/cs7004.vk.me\/v7004692\/1af43\/msvfzwgm5tc.jpg","width":604,"height":302,"text":"Наука<br>http:\/\/vk.com\/public65923388","created":1456235510,"access_key":"d1cff88abc28e29b28"}},{"type":"photo","photo":{"pid":404384428,"aid":223686536,"owner_id":-65923388,"user_id":100,"src":"http:\/\/cs7004.vk.me\/v7004365\/1a9ff\/3tEb3pm-bBA.jpg","src_big":"http:\/\/cs7004.vk.me\/v7004365\/1aa00\/LIQOncL-su8.jpg","src_small":"http:\/\/cs7004.vk.me\/v7004365\/1a9fe\/TKchasZfhNo.jpg","width":604,"height":585,"text":"Наука<br>http:\/\/vk.com\/public65923388","created":1456235512,"access_key":"e9370296ef33bebb7a"}},{"type":"photo","photo":{"pid":404384439,"aid":223686536,"owner_id":-65923388,"user_id":100,"src":"http:\/\/cs7004.vk.me\/v7004767\/1ab36\/1IqODh-OmS0.jpg","src_big":"http:\/\/cs7004.vk.me\/v7004767\/1ab37\/3M52LmF_dY8.jpg","src_small":"http:\/\/cs7004.vk.me\/v7004767\/1ab35\/lOR1yvNeE8Y.jpg","width":478,"height":604,"text":"Наука<br>http:\/\/vk.com\/public65923388","created":1456235514,"access_key":"8cc1048e72e29b8ced"}},{"type":"photo","photo":{"pid":404384504,"aid":223686536,"owner_id":-65923388,"user_id":100,"src":"http:\/\/cs7004.vk.me\/v7004474\/1b385\/wdi9GlRth20.jpg","src_big":"http:\/\/cs7004.vk.me\/v7004474\/1b386\/I5PY-gN_xa4.jpg","src_small":"http:\/\/cs7004.vk.me\/v7004474\/1b384\/HkzVl-hsZUo.jpg","width":604,"height":419,"text":"Наука<br>http:\/\/vk.com\/public65923388","created":1456235537,"access_key":"5d5ca96b04e91e2744"}},{"type":"photo","photo":{"pid":404384509,"aid":223686536,"owner_id":-65923388,"user_id":100,"src":"http:\/\/cs7004.vk.me\/v7004452\/1a619\/nDL7Q9dJhxs.jpg","src_big":"http:\/\/cs7004.vk.me\/v7004452\/1a61a\/PaJXcLeD5Aw.jpg","src_small":"http:\/\/cs7004.vk.me\/v7004452\/1a618\/-h36pYEcpPY.jpg","width":604,"height":292,"text":"Наука<br>http:\/\/vk.com\/public65923388","created":1456235540,"access_key":"ae318183e5303414e9"}}],"comments":{"count":0},"likes":{"count":127},"reposts":{"count":45}}]}
  6. JSON;
  7.  
  8. $myObject = json_decode($myJson);
  9. foreach($myObject->response AS $index=>$item)
  10. {
  11. //print_r($item); //Remove comment to see your item
  12. foreach($item->attachments AS $attachment)
  13. {
  14. echo "attachment:";
  15. print_r($attachment);
  16. }
  17. }
Success #stdin #stdout 0.03s 52480KB
stdin
Standard input is empty
stdout
attachment:stdClass Object
(
    [type] => photo
    [photo] => stdClass Object
        (
            [pid] => 404384423
            [aid] => 223686536
            [owner_id] => -65923388
            [user_id] => 100
            [src] => http://c...content-available-to-author-only...k.me/v7004692/1af44/5zhYes1I7xg.jpg
            [src_big] => http://c...content-available-to-author-only...k.me/v7004692/1af45/QRt-0dPZ8qg.jpg
            [src_small] => http://c...content-available-to-author-only...k.me/v7004692/1af43/msvfzwgm5tc.jpg
            [width] => 604
            [height] => 302
            [text] => Наука<br>http://content-available-to-author-only.com/public65923388
            [created] => 1456235510
            [access_key] => d1cff88abc28e29b28
        )

)
attachment:stdClass Object
(
    [type] => photo
    [photo] => stdClass Object
        (
            [pid] => 404384428
            [aid] => 223686536
            [owner_id] => -65923388
            [user_id] => 100
            [src] => http://c...content-available-to-author-only...k.me/v7004365/1a9ff/3tEb3pm-bBA.jpg
            [src_big] => http://c...content-available-to-author-only...k.me/v7004365/1aa00/LIQOncL-su8.jpg
            [src_small] => http://c...content-available-to-author-only...k.me/v7004365/1a9fe/TKchasZfhNo.jpg
            [width] => 604
            [height] => 585
            [text] => Наука<br>http://content-available-to-author-only.com/public65923388
            [created] => 1456235512
            [access_key] => e9370296ef33bebb7a
        )

)
attachment:stdClass Object
(
    [type] => photo
    [photo] => stdClass Object
        (
            [pid] => 404384439
            [aid] => 223686536
            [owner_id] => -65923388
            [user_id] => 100
            [src] => http://c...content-available-to-author-only...k.me/v7004767/1ab36/1IqODh-OmS0.jpg
            [src_big] => http://c...content-available-to-author-only...k.me/v7004767/1ab37/3M52LmF_dY8.jpg
            [src_small] => http://c...content-available-to-author-only...k.me/v7004767/1ab35/lOR1yvNeE8Y.jpg
            [width] => 478
            [height] => 604
            [text] => Наука<br>http://content-available-to-author-only.com/public65923388
            [created] => 1456235514
            [access_key] => 8cc1048e72e29b8ced
        )

)
attachment:stdClass Object
(
    [type] => photo
    [photo] => stdClass Object
        (
            [pid] => 404384504
            [aid] => 223686536
            [owner_id] => -65923388
            [user_id] => 100
            [src] => http://c...content-available-to-author-only...k.me/v7004474/1b385/wdi9GlRth20.jpg
            [src_big] => http://c...content-available-to-author-only...k.me/v7004474/1b386/I5PY-gN_xa4.jpg
            [src_small] => http://c...content-available-to-author-only...k.me/v7004474/1b384/HkzVl-hsZUo.jpg
            [width] => 604
            [height] => 419
            [text] => Наука<br>http://content-available-to-author-only.com/public65923388
            [created] => 1456235537
            [access_key] => 5d5ca96b04e91e2744
        )

)
attachment:stdClass Object
(
    [type] => photo
    [photo] => stdClass Object
        (
            [pid] => 404384509
            [aid] => 223686536
            [owner_id] => -65923388
            [user_id] => 100
            [src] => http://c...content-available-to-author-only...k.me/v7004452/1a619/nDL7Q9dJhxs.jpg
            [src_big] => http://c...content-available-to-author-only...k.me/v7004452/1a61a/PaJXcLeD5Aw.jpg
            [src_small] => http://c...content-available-to-author-only...k.me/v7004452/1a618/-h36pYEcpPY.jpg
            [width] => 604
            [height] => 292
            [text] => Наука<br>http://content-available-to-author-only.com/public65923388
            [created] => 1456235540
            [access_key] => ae318183e5303414e9
        )

)