I would need help:
I have an array and I need to get values from it…but how to get the data which are within curly brackets …
It should be something simple, I think … I tried with explode which obviously cannot work as I have for example within last curly brackets with two kinds of data, which should be distinguished as so…each curly bracket (with data applies to something).
$array = array(
"other" => "{name:2},{value:2},{align:4},{height:4, color:red}",
"another" => "{name:2},{value:2},{align:4},{height:4, color:red}"
);
I’m really struggling … and appreciate your help.
Thanks
On the contrary, I think explode will work perfectly. Explode into separate strings and then for each string retrieve from index 1 to index [arraylength-1] since index 0 contains { and the last index contains }.
$str = substr($str, 1, strlen($str)-1);So for each string cut out from index 1 to last_index-1.
EDIT:
AFter you do the first explode (which will cut it into 2 big chunks): chunk1 and chunk2
foreach chunk array// or chunk 2 (this will further cut the pieces up into strings that were separated by ,)$pieces=explode(",",$chunk1);
$str = substr($pieces, 1, strlen($pieces)-1);Then for each $piece, retrieve the content in between. (pseudo code)