note 100863 deleted from ref.pgsql by danbrown
| From: | danbrown@php.net | Date: | Thu, 11 Nov 2010 18:33:23 +0000 |
| Subject: | note 100863 deleted from ref.pgsql by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-173954@lists.php.net to get a copy of this message | ||
Note Submitter: spidgorny at gmail dot com
----
In response to http://www.php.net/manual/en/ref.pgsql.php#57709.
Your PGArrayToPHPArray() doesn't take care of commas inside the quoted string. Here's my
version (single-dimension arrays only).
<?php
function getPGArray($pgArray) {
$pgArray = substr(substr(trim($pgArray), 1), 0, -1);
$v1 = explode(',', $pgArray);
$inside = false;
$out = array();
$o = 0;
foreach ($v1 as $word) {
if ($word{0} == '"') {
$inside = true;
$word = substr($word, 1);
}
if ($word{strlen($word)-1} == '"') {
$inside = false;
$word = substr($word, 0, -1);
}
$out[$o] .= stripslashes(stripslashes($word)); // strange but required
if (!$inside) {
$o++;
}
}
return $out;
}
?>
debug(getPGArray('{BOOT6.INI,"strange нейм
{\\'=â ,.\\'}.info","strange нейм
{\\'=â ,.\\'}1.info"}')); will return
<?php
Array
(
[0] => BOOT6.INI
[1] => strange нейм {'=â .'}.info
[2] => strange нейм {'=â .'}1.info
)
?>