|
Posted by Kim Andrι Akerψ on 01/25/07 11:41
Nick Wedd wrote:
> 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?
This approach might work, too:
$cs_pairs = explode("!", $cookiestring);
foreach ($cs_pairs as $pair) {
$vals = explode("=", $pair);
$r[$vals[0]] = $vals[1];
}
--
Kim AndrΓ© AkerΓΈ
- kimandre@NOSPAMbetadome.com
(remove NOSPAM to contact me directly)
Navigation:
[Reply to this message]
|