note 80134 added to function.explode
| From: | HugoR dot GomezC dot at osu1 dot php dot net | Date: | Mon, 31 Dec 2007 01:08:38 +0000 |
| Subject: | note 80134 added to function.explode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-134577@lists.php.net to get a copy of this message | ||
Here's a fancier version of Saurabh Sahni's explode_assoc function.
<?
function explode_assoc($major_sep,$minor_sep,$str)
{
$params = explode($major_sep,$str);
foreach ($params as $entry)
{
list($key,$value) = explode($minor_sep,$entry);
$result[trim($key)] = trim($value);
}
return $result;
}
//Sample usage:
$response = explode_assoc('&',':','title:Recent
News&color:black&style:bold');
print_r($response);
?>
This outputs:
Array
(
[title] => Recent News
[color] => black
[style] => bold
)
----
Server IP: 69.147.83.197
Probable Submitter: 201.143.26.83
----
Manual Page -- http://www.php.net/manual/en/function.explode.php
Edit -- https://master.php.net/note/edit/80134
Del: integrated -- https://master.php.net/note/delete/80134/integrated
Del: useless -- https://master.php.net/note/delete/80134/useless
Del: bad code -- https://master.php.net/note/delete/80134/bad+code
Del: spam -- https://master.php.net/note/delete/80134/spam
Del: non-english -- https://master.php.net/note/delete/80134/non-english
Del: in docs -- https://master.php.net/note/delete/80134/in+docs
Del: other reasons-- https://master.php.net/note/delete/80134
Reject -- https://master.php.net/note/reject/80134
Search -- https://master.php.net/manage/user-notes.php