note 89841 added to ref.pgsql

From: Date: Wed, 25 Mar 2009 17:12:07 +0000
Subject: note 89841 added to ref.pgsql
Groups: php.notes 
Request: Send a blank email to php-notes+get-152434@lists.php.net to get a copy of this message
Parsing a postgres array can be a tricky problem, he's my take on this, it handles multi-dimensional arrays plus escaping using a nasty regexp to determine the limits of each data-item. function pg_array_parse( $text, &$output, $limit = false, $offset = 1 ) { if( false === $limit ) { $limit = strlen( $text )-1; $output = array(); } if( '{}' != $text ) do { if( '{' != $text{$offset} ) { preg_match( "/(\\{?\"([^\"\\\\]|\\\\.)*\"|[^,{}]+)+([,}]+)/", $text, $match, 0, $offset ); $offset += strlen( $match[0] ); $output[] = ( '"' != $match[1]{0} ? $match[1] : stripcslashes( substr( $match[1], 1, -1 ) ) ); if( '},' == $match[3] ) return $offset; } else $offset = pg_array_parse( $text, $output[], $limit, $offset+1 ); } while( $limit > $offset ); return $output; } ---- Server IP: 92.48.74.199 Probable Submitter: 217.41.54.129 ---- Manual Page -- http://www.php.net/manual/en/ref.pgsql.php Edit -- https://master.php.net/note/edit/89841 Del: integrated -- https://master.php.net/note/delete/89841/integrated Del: useless -- https://master.php.net/note/delete/89841/useless Del: bad code -- https://master.php.net/note/delete/89841/bad+code Del: spam -- https://master.php.net/note/delete/89841/spam Del: non-english -- https://master.php.net/note/delete/89841/non-english Del: in docs -- https://master.php.net/note/delete/89841/in+docs Del: other reasons-- https://master.php.net/note/delete/89841 Reject -- https://master.php.net/note/reject/89841 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#152434) next »