1

I am struggling with converting a string into an array:

["Пятницкое шоссе","Митино","Волоколамская","Планерная","Сходненская"]

and I want to convert it into an array of values inside quotes "".

Tried (un)serialize(), parse_str(). They don't cope with it.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Denis Evseev
  • 1,660
  • 1
  • 18
  • 33

2 Answers2

3

Since nobody else is going to post it, that looks like JSON:

$array = json_decode($string, true);
print_r($array);

The true parameter isn't needed for this JSON, but if you want to make sure you always get an array and not an object regardless of the JSON then use it.

AbraCadaver
  • 78,200
  • 7
  • 66
  • 87
2

It would be easiest to use json_decode:

json_decode('["Пятницкое шоссе","Митино","Волоколамская","Планерная","Сходненская"]', true)

But if for some reason you are not parsing is as json, you should be able to use explode:

explode(',', '"Пятницкое шоссе","Митино","Волоколамская","Планерная","Сходненская"');

If you need to deal with the brackets, you can trim them from the string with something like this prior to exploding:

$string = trim('["Пятницкое шоссе","Митино","Волоколамская","Планерная","Сходненская"]', '[]');
kjones
  • 1,339
  • 1
  • 13
  • 28