-2

I want to apply the regex to extract only the values. I am not getting the perfect one any help

[{"name":"basket ball"},{"name":"foot ball"},{"name":"sports"}]
Jeff
  • 6,895
  • 1
  • 15
  • 33
an__snatcher
  • 121
  • 2
  • 12
  • If you have an array of objects like that, `array_column` can be handy to get the values from a single key like "name" (after you json_decode). – Don't Panic Nov 27 '18 at 23:32

1 Answers1

1

There's absolutely no need for a regex here. Use json_decode():

$string = '[{"name":"basket ball"},{"name":"foot ball"},{"name":"sports"}]';
$data = json_decode($string, true);

now you have a normal php array $data to get your wanted data from.
like

echo $data[0]['name']; // basket ball
Jeff
  • 6,895
  • 1
  • 15
  • 33