php - How to preg match to parse the value addr: in this string -
i got string of blockchain of below
{"double_spend":false,"block_height":294529,"time":1396809215,"inputs":[{"prev_out":{"n":1,"value":68000,"addr":"1zzzzhhdll5zked9gbakpt4j3vzgumvhg","tx_index":53988341,"type":0,"script":"76a91406287de03de2b4cdd4095ce75c4101004677876b88ac"},"script":"76a91406287de03de2b4cdd4095ce75c4101004677876b88ac"}],"vout_sz":2,"relayed_by":"107.170.67.24","hash":"5f63a2dcbef2e534934b1919430d2ccafa030ec1f8011581a58b43b1d529db5e","vin_sz":1,"tx_index":54014213,"ver":1,"out":[{"n":0,"value":10000,"addr":"1l3zer3u5qg8zz59c3td9ecuwekeszcvnf","tx_index":54014213,"spent":true,"type":0,"script":"76a914d0e6208c2d26e09ff8b51c1b5ba12b4dcf66b71f88ac"},{"n":1,"value":48000,"addr":"1zzzzhhdll5zked9gbakpt4j3vzgumvhg","tx_index":54014213,"spent":true,"type":0,"script":"76a91406287de03de2b4cdd4095ce75c4101004677876b88ac"}],"size":258}
how parse value of "addr": array
the print_r of array should return
[0] 1zzzzhhdll5zked9gbakpt4j3vzgumvhg [1] 1l3zer3u5qg8zz59c3td9ecuwekeszcvnf [2] 1zzzzhhdll5zked9gbakpt4j3vzgumvhg
thank helping!
instead of regex, use json_decode
input looks json
$arr = array(); $json = json_decode($text); // $text input foreach($json->inputs $x){ array_push($arr, $x->prev_out->addr); } foreach($json->out $x){ array_push($arr, $x->addr); } print_r($arr);
Comments
Post a Comment