I have this data:
{"names":["George","Eric","Alice"]}
And I want to use preg_match_all to filter out the words in between quotation like this:
$s = $data;
if (preg_match_all('/"([^:]*)"/', $s, $matches)) {
echo join("\n", $matches[1]);
}
But this is outputting names George","Eric","Alice I tried many things but I cant figure it out.
json_decode()to the rescueprint_r(json_decode('{"names":["George","Eric","Alice"]}', true));!join().foreach($arr, $key => $value){}loop, it actually depends on how random your source is. Anyways, parsing JSON with regex isn't "recommended" it's still possible with regex though