Well, it’s really hard to explain in English, so I’ll just give an example.
I will have lines in the following format:
key-value;key1-value;key2-...
and I need to extract the data as an array
array('key'=>'value','key1'=>'value1', ... )
I planned to use regexp to achieve (for the most part) this function and wrote this regex:
/^(\w+)-([^-;]+)(?:;(\w+)-([^-;]+))*;?$/
to work with preg_matchand with this code:
for ($l = count($matches),$i = 1;$i<$l;$i+=2) {
$parameters[$matches[$i]] = $matches[$i+1];
}
However, regexp explicitly returns only 4 backlinks - the first and last key-value pairs of the input string. Is there any way around this? I know that I can use a regular expression only to validate a string and use PHP explodein loops with excellent results, but I'm really wondering if this is possible with regular expressions.
, key-value; .