note 58660 added to ref.pgsql

From: Date: Fri, 11 Nov 2005 01:17:14 +0000
Subject: note 58660 added to ref.pgsql
Groups: php.notes 
Request: Send a blank email to php-notes+get-98411@lists.php.net to get a copy of this message
Here is a better array parser for PHP. It will work with 1-d arrays only. Unlike the example below it will work in all cases. /** * Change a db array into a PHP array * @param $arr String representing the DB array * @return A PHP array */ function phpArray($dbarr) { // Take off the first and last characters (the braces) $arr = substr($dbarr, 1, strlen($dbarr) - 2); // Pick out array entries by carefully parsing. This is necessary in order // to cope with double quotes and commas, etc. $elements = array(); $i = $j = 0; $in_quotes = false; while ($i < strlen($arr)) { // If current char is a double quote and it's not escaped, then // enter quoted bit $char = substr($arr, $i, 1); if ($char == '"' && ($i == 0 || substr($arr, $i - 1, 1) != '\\')) $in_quotes = !$in_quotes; elseif ($char == ',' && !$in_quotes) { // Add text so far to the array $elements[] = substr($arr, $j, $i - $j); $j = $i + 1; } $i++; } // Add final text to the array $elements[] = substr($arr, $j); // Do one further loop over the elements array to remote double quoting // and escaping of double quotes and backslashes for ($i = 0; $i < sizeof($elements); $i++) { $v = $elements[$i]; if (strpos($v, '"') === 0) { $v = substr($v, 1, strlen($v) - 2); $v = str_replace('\\"', '"', $v); $v = str_replace('\\\\', '\\', $v); $elements[$i] = $v; } } return $elements; } ---- Manual Page -- http://www.php.net/manual/en/ref.pgsql.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+58660 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+58660&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+58660&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+58660&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+58660&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+58660&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+58660&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+58660&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+58660&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#98411) next »