note 39047 deleted from ref.pgsql by tomsommer

From: Date: Thu, 15 Jan 2004 17:47:01 +0000
Subject: note 39047 deleted from ref.pgsql by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-63634@lists.php.net to get a copy of this message
Note Submitter: onno@straw_no_spam_berries.nl ---- 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; }

« previous php.notes (#63634) next »