String to Array or Hash Table

From: Date: Sun, 19 Oct 2003 09:45:46 +0000
Subject: String to Array or Hash Table
Groups: php.general 
Request: Send a blank email to php-general+get-166651@lists.php.net to get a copy of this message
Hi, all, The question is concerning a feedback String from a web-service. "approved=yes&error=&authnumber=025968&transactionnumber=313869" As you c, the String contains four parameters.. I explode it first by "&". $execoutput = "approved=yes&error=&authnumber=025968&transactionnumber=313869"; $execoutput_array = explode("&", $execoutput); I secondly explode every parameter=value string by "=".. for (@reset($execoutput_array); list($key,$value)=@each($execoutput_array);) { #output the result for debugging $value_array = explode("=", $value); for (@reset($value_array); list($key1,$value1)=@each($value_array);) {
     $first = $value1;
     list($key1,$value1)=@each($value_array);
     $second = $value1;
     if($first == "approved")
     {
       $approved = $second;
     }
     if($first == "error")
     {
       $error = $second;
     }
     if($first == "authnumber")
     {
       $authnumber = $second;
     }
     if($first == "transactionnumber")
     {
       $transactionnumber = $second;
     }
} } However, this way looks quite ugly.. I expect to get a concise code.. could you pls help me? with best wishes Zheng Sun _________________________________________________________________ Tired of spam? Get advanced junk mail protection with MSN 8. http://join.msn.com/?page=features/junkmail

« previous php.general (#166651) next »