|
Posted by Nick Wedd on 01/25/07 10:48
I have a string, $cookiestring, which typically looks like this:
"us=1!uk=2!de=13!fr=8!". I want to use this to get values into an array
$r, so that $r['us']=1, $r['uk']=2, etc.
Here is how I have achieved it:
preg_match_all( "/(..)=(\d+)!/", $cookiestring, $res );
for ( $i=0 ; $i<sizeof( $res[1] ) ; $i++ ) {
eval( "$" . "r[\"" . $res[1][$i] . "\"]=". $res[2][$i] . ";" );
}
I think my use of eval is pretty horrible, and feel that there must be a
better way. But I can't get anything else to work. Can anyone advise?
Nick
--
Nick Wedd nick@maproom.co.uk
Navigation:
[Reply to this message]
|