Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

regex get number betwen quotes

i have difrent string json type egz formats in line

{"env":"stato","usc":"00000000","isc":"000100","sn":"0120xxxxmacxxx"}
{{"cmd":"stat"},{"usc":"00000000",{"isc":"1001000"}},"sn":"0120xxxxmacxxx"}
{{"cmd":"status","usc":"00000000","isc":"1110001"},"sn":"0120xxxxmacxxx"}
{'stat':'dev',{data:['usc':'00000000','isc':'10010001']},'sn':'0120xxxxmacxxx'}

need single regex by get only numbers 0-1 format in quotes after "isc":"NEED THIS NUMBERS ONLY" in single php regex for all formats.
egs

$json = '{"env":"stato","usc":"00000000","isc":"00010000","sn":"0120xxxxmacxxx"}';
$find = "isc";    
function find_data($find,$json){
  preg_match('/("'.$find.'":"[^"]*"|^[^"]*$)/i',  $json, $ref, PREG_OFFSET_CAPTURE);
  return $ref;
}

json loop solution does not come! json search can only be accepted on one line of code,
I have limited computing and memory resources in atmega 16

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

thx for help

>Solution :

$json = '{"env":"stato","usc":"00000000","isc":"00010000","sn":"0120xxxxmacxxx"}';

$arr = json_decode($json);
$isc = $arr->isc;

print_r($isc);   // Prints:   00010000
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading