php - Best way to parse this string and create an array from it -


i have follow string:

{item1:test},{item2:hi},{another:please work} 

what want turn array looks this:

[item1] => test [item2] => hi [another] => please work 

here code using (which works):

$vf = '{item1:test},{item2:hi},{another:please work}'; $vf = ltrim($vf, '{'); $vf = rtrim($vf, '}'); $vf = explode('},{', $vf);  foreach ($vf $vk => $vv) {     $ve = explode(':', $vv);     $vx[$ve[0]] = $ve[1]; } 

my concern is; if value has colon in it? example, lets value item1 you:break. colon going make me lose break entirely. better way of coding in case value has colon in it?

why not set limit on explode function. this:

$ve = explode(':', $vv, 2); 

this way string split @ first occurrence of colon.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

gradle error "Cannot convert the provided notation to a File or URI" -