note 78590 deleted from function.parse-ini-file by tularis
| From: | tularis@php.net | Date: | Thu, 18 Oct 2007 14:18:57 +0000 |
| Subject: | note 78590 deleted from function.parse-ini-file by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-131501@lists.php.net to get a copy of this message | ||
Note Submitter: root at mantoru dot de
----
This very handy function can be used to parse comma separated var=val strings, even with quotes: a =
"b, c, d", into an array.
I DID NOT DO IT MYSELF. Just stumbled upon it. Full credit goes to flyspray.org (and of course the
phpBB Group, which modified it).
<?php
// Modified version from phpBB-3.0.RC7
// /phpBB3/includes/functions_jabber.php, line 718
function parse_data($data)
{
$data = explode(',', $data);
$pairs = array();
$key = false;
foreach ($data as $pair)
{
$dd = strpos($pair, '=');
if ($dd)
{
$key = trim(substr($pair, 0, $dd));
$pairs[$key] = trim(trim(substr($pair, $dd + 1)), '"');
}
else if (strpos(strrev(trim($pair)), '"') === 0 && $key)
{
// We are actually having something left from "a, b" values, add it to the last one we
handled.
$pairs[$key] .= ',' . trim(trim($pair), '"');
continue;
}
}
return $pairs;
}
?>