parse json from url using php and save in mysql db -


i've json response web service

{   "success":true,   "timestamp":1503291248,   "quotes":{     "sad":"abc",     "love":"xyz",     "friendship":"some",     "enmity":"lorem ipsum",     ... //indicates there lot more categories   } } 

i have tried echo data using script

<?php     $url = 'my_url';     $content = file_get_contents($url);     $json = json_decode($content, true);      foreach ( $json $idx=>$json ) {        echo $idx;     } ?> 

this prints

successtermsprivacytimestampsourcequotes 

but getting empty response, how can echo/save above josn data in mysql?

<?php     $url = '{   "success":true,   "timestamp":1503291248,   "quotes":{     "sad":"abc",     "love":"xyz",     "friendship":"some",     "enmity":"lorem ipsum",     ... //indicates there lot more categories   } }';     $content = file_get_contents($url);     $json = json_decode($content, true);      foreach ( $json $idx=>$json ) {        if(is_array($json))        {          foreach($json $iidx=>$jjson)           {              echo $iidx.":".$jjson;          }        }        else        {          echo $idx.":".$json;        }     }      $ins_qry = 'insert json_table(jsonvalues) values ("'.$json.'")';     $exec_qry = mysqli_query($link,$ins_qry); ?> 

this print json data. save json data in mysql, can directly insert $json value text column of mysql table.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -