note 100257 added to ref.pgsql
| From: | n dot can dot kirik at gmail dot com | Date: | Mon, 04 Oct 2010 18:37:51 +0000 |
| Subject: | note 100257 added to ref.pgsql | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-172948@lists.php.net to get a copy of this message | ||
parsing pg arrays tricky. how about parsing arrays of hstores? or hstore values contains arrays?
here is my solution inspired by veggivore at yahoo dot com:
it handles all the variations, etc. array of hstores of arrays...
<?php
function toArray( $input ) {
if ( preg_match( '/^"?[\w\s\d\.]+"?$/', $input ) > 0 ) return $input;
if ( $input == '{}' ) return array();
$input = trim( $input, '{}' );
$output = @eval( 'return array(' . $input . ');' );
if ( $output ) foreach( $output as $k => &$v ) $v = toArray( $v );
if ( !$output ) $output = $input;
return $output;
}
?>
here there is a Turkish edition:
<?php
function diziyeÃevir( $girdi ) {
if ( preg_match( '/^"?[\w\s\d\.]+"?$/', $girdi ) > 0 ) return $girdi;
if ( $girdi == '{}' ) return array();
$girdi = trim( $girdi, '{}' );
$çıktı = @eval( 'return array(' . $girdi . ');' );
if ( $çıktı ) foreach( $çıktı as $k => &$v ) $v = diziyeÃevir( $v );
if ( !$çıktı ) $çıktı = $girdi;
return $çıktı;
}
?>
(maybe regexp won't fit for you.)
----
Server IP: 160.75.100.7
Probable Submitter: 193.255.130.65
----
Manual Page -- http://www.php.net/manual/en/ref.pgsql.php
Edit -- https://master.php.net/note/edit/100257
Del: integrated -- https://master.php.net/note/delete/100257/integrated
Del: useless -- https://master.php.net/note/delete/100257/useless
Del: bad code -- https://master.php.net/note/delete/100257/bad+code
Del: spam -- https://master.php.net/note/delete/100257/spam
Del: non-english -- https://master.php.net/note/delete/100257/non-english
Del: in docs -- https://master.php.net/note/delete/100257/in+docs
Del: other reasons-- https://master.php.net/note/delete/100257
Reject -- https://master.php.net/note/reject/100257
Search -- https://master.php.net/manage/user-notes.php