note 79799 added to function.explode

From: Date: Thu, 13 Dec 2007 12:20:09 +0000
Subject: note 79799 added to function.explode
Groups: php.notes 
Request: Send a blank email to php-notes+get-133416@lists.php.net to get a copy of this message
An extension to explode can be explode_assoc. This is reverse of implode_assoc return by Brian and can be found with implode. <?php function explode_assoc($glue1, $glue2, $array) { $array2=explode($glue2, $array); foreach($array2 as $val) { $pos=strpos($val,$glue1); $key=substr($val,0,$pos); $array3[$key] =substr($val,$pos+1,strlen($val)); } return $array3; } //usage: $str="key1=val1&key2=val2&key3=val3"; $array=explode_assoc('=','&',$str); print_r($array); ?> This outputs: Array ( [key1] => val1 [key2] => val2 [key3] => val3 ) ---- Server IP: 203.199.69.133 Probable Submitter: 203.83.248.32 ---- Manual Page -- http://www.php.net/manual/en/function.explode.php Edit -- https://master.php.net/note/edit/79799 Del: integrated -- https://master.php.net/note/delete/79799/integrated Del: useless -- https://master.php.net/note/delete/79799/useless Del: bad code -- https://master.php.net/note/delete/79799/bad+code Del: spam -- https://master.php.net/note/delete/79799/spam Del: non-english -- https://master.php.net/note/delete/79799/non-english Del: in docs -- https://master.php.net/note/delete/79799/in+docs Del: other reasons-- https://master.php.net/note/delete/79799 Reject -- https://master.php.net/note/reject/79799 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#133416) next »