note 78590 added to function.parse-ini-file

From: Date: Thu, 18 Oct 2007 10:56:45 +0000
Subject: note 78590 added to function.parse-ini-file
Groups: php.notes 
Request: Send a blank email to php-notes+get-131491@lists.php.net to get a copy of this message
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; } ?> ---- Server IP: 217.13.201.10 Probable Submitter: 85.179.61.213 ---- Manual Page -- http://www.php.net/manual/en/function.parse-ini-file.php Edit -- https://master.php.net/note/edit/78590 Del: integrated -- https://master.php.net/note/delete/78590/integrated Del: useless -- https://master.php.net/note/delete/78590/useless Del: bad code -- https://master.php.net/note/delete/78590/bad+code Del: spam -- https://master.php.net/note/delete/78590/spam Del: non-english -- https://master.php.net/note/delete/78590/non-english Del: in docs -- https://master.php.net/note/delete/78590/in+docs Del: other reasons-- https://master.php.net/note/delete/78590 Reject -- https://master.php.net/note/reject/78590 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#131491) next »