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.

0

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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('["Пятницкое шоссе","Митино","Волоколамская","Планерная","Сходненская"]', '[]');

1 Comment

Thanks, kjones for the answer! trim and explode examples are quite useful!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.