note 106251 deleted from ref.pgsql by danbrown
| From: | danbrown@php.net | Date: | Fri, 21 Oct 2011 15:09:57 +0000 |
| Subject: | note 106251 deleted from ref.pgsql by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-184050@lists.php.net to get a copy of this message | ||
Note Submitter: koleo.com
----
The (great) function pg_array_parse() from "cc+php" does not work with utf8 strings and
special chars.
The offset parameter of the preg_match() function needs a number of bytes, not a number of
characters.
This function should work better (replacing strlen with mb_strlen($xxx, '8bit')) :
<?php
function pg_array_parse( $text, &$output, $limit = false, $offset = 1 )
{
if( false === $limit )
{
$limit = mb_strlen( $text, '8bit' )-1;
$output = array();
}
if( '{}' != $text )
do
{
if( '{' != $text{$offset} )
{
preg_match( "/(\\{?\"([^\"\\\\]|\\\\.)*\"|[^,{}]+)+([,}]+)/",
$text, $match, 0, $offset );
$offset += mb_strlen( $match[0], '8bit' );
$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;
}
?>