String to associative array
I'm having trouble using preg_match_all to split a string into key value
pairs. An example of my string:
"%Title:Movie%Sortable%Writer:%Indexed:false%"
Where I expect results like:
$result['Title'] = 'Movie';
$result['Sortable'] = '';
$result['Writer'] = '';
$result['Indexed'] = 'false';
I can split the string using
preg_match('/%/',$str,-1,PREG_SPLIT_NO_EMPTY); but it returns an indexed
array. I need an associative array so that order is not important and I
can use the key in a switch statement. What would be the correct regex to
use in preg_match_all?
No comments:
Post a Comment