note 39047 added to ref.pgsql
| From: | onno at straw_no_spam_berries dot nl | Date: | Thu, 15 Jan 2004 12:42:23 +0000 |
| Subject: | note 39047 added to ref.pgsql | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-63603@lists.php.net to get a copy of this message | ||
Here two functions to convert from/to arrays:
function array_to_pgsql($array) {
foreach ($array as $val) {
$val = addslashes($val);
$val = str_replace('\\', '\\\\', $val);
$ret .= "\"${val}\",";
}
return '{' . substr($ret, 0, -1) . '}';
}
function pgsql_to_array($line) {
$line = substr($line, 1, -1);
$fields = array();
$inquotes = false;
$current_field;
for ($i = 0; $i < strlen($line); $i++) {
switch ($line[$i]) {
case '\\':
if ($line[$i+1] == '\\') {
$current_field .= '\\';
$i++;
break;
// FALL_THROUGH
} else {
//append next and increase i;
$current_field .= $line[++$i];
break;
}
case '"':
$inquotes = !$inquotes;
break;
case ',':
if ($inquotes) {
// FALL_THROUGH
} else {
// new item
array_push($fields, $current_field);
$current_field = "";
break;
}
default:
// append
$current_field .= $line[$i];
break;
}
}
array_push($fields, $current_field);
return $fields;
}
----
Manual Page -- http://www.php.net/manual/en/ref.pgsql.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+39047
Delete -- http://master.php.net/manage/user-notes.php?action=delete+39047&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+39047&report=yes
Search -- http://master.php.net/manage/user-notes.php