note 93324 added to function.explode

From: Date: Thu, 03 Sep 2009 02:18:59 +0000
Subject: note 93324 added to function.explode
Groups: php.notes 
Request: Send a blank email to php-notes+get-160185@lists.php.net to get a copy of this message
<?php // converts pure string into a trimmed keyed array function string2KeyedArray($string, $delimiter = ',', $kv = '=>') { if ($a = explode($delimiter, $string)) { // create parts foreach ($a as $s) { // each part if ($s) { if ($pos = strpos($s, $kv)) { // key/value delimiter $ka[trim(substr($s, 0, $pos))] = trim(substr($s, $pos + strlen($kv))); } else { // key delimiter not found $ka[] = trim($s); } } } return $ka; } } // string2KeyedArray $string = 'a=>1, b=>23 , $a, c=> 45% , true,d => ab c '; print_r(string2KeyedArray($string)); ?> Array ( [a] => 1 [b] => 23 [0] => $a [c] => 45% [1] => true [d] => ab c ) ---- Server IP: 64.71.164.2 Probable Submitter: 76.216.115.221 ---- Manual Page -- http://www.php.net/manual/en/function.explode.php Edit -- https://master.php.net/note/edit/93324 Del: integrated -- https://master.php.net/note/delete/93324/integrated Del: useless -- https://master.php.net/note/delete/93324/useless Del: bad code -- https://master.php.net/note/delete/93324/bad+code Del: spam -- https://master.php.net/note/delete/93324/spam Del: non-english -- https://master.php.net/note/delete/93324/non-english Del: in docs -- https://master.php.net/note/delete/93324/in+docs Del: other reasons-- https://master.php.net/note/delete/93324 Reject -- https://master.php.net/note/reject/93324 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#160185) next »