Shaolin
Shaolin

Reputation: 2551

Efficient way to split a string into an array - PHP

What is the best way to split the below $string to get the array $cars in PHP?

$string = '{xa}{y}{z12}{123}{2}{aabb}';

$cars = array("{xa}","{y}","{z12}", "{123}", "{2}", "{aabb}");

I need each array element with brackets eg : {xa}

Upvotes: 0

Views: 64

Answers (1)

Alex W
Alex W

Reputation: 38173

$string = str_replace("}{","},{",$string);
$x = explode(',',$string);

Upvotes: 5

Related Questions