I was wondering if anyone here could help me. I have the following string:
$str = 'unit1(field1,field2,field3),unit2(field4,field5,field6)';
I am trying to parse this string to create the following array:
array(
'unit1' => array('field1', 'field2', 'field3')
'unit2' => array('field4', 'field5', 'field6')
)
I am pretty hopeless with regex so I am not even sure where to start with this.
Thanks
unit2
? – John Jul 17 at 3:18preg_match
andpreg_match_all
on the PHP docs. Once you read all that try to build your own solution and come back with the code that failed and somebody might help. – elclanrs Jul 17 at 3:19[{"unit":"unit1", "fields":["field1","field2"]},...]
andjson_decode($str)
? – Jan Dvorak Jul 17 at 3:57