note 106251 added to ref.pgsql

From: Date: Fri, 21 Oct 2011 14:46:00 +0000
Subject: note 106251 added to ref.pgsql
Groups: php.notes 
Request: Send a blank email to php-notes+get-184046@lists.php.net to get a copy of this message
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; } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 82.236.141.76 ---- Manual Page -- http://www.php.net/manual/en/ref.pgsql.php Edit -- https://master.php.net/note/edit/106251 Del: integrated -- https://master.php.net/note/delete/106251/integrated Del: useless -- https://master.php.net/note/delete/106251/useless Del: bad code -- https://master.php.net/note/delete/106251/bad+code Del: spam -- https://master.php.net/note/delete/106251/spam Del: non-english -- https://master.php.net/note/delete/106251/non-english Del: in docs -- https://master.php.net/note/delete/106251/in+docs Del: other reasons-- https://master.php.net/note/delete/106251 Reject -- https://master.php.net/note/reject/106251 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#184046) next »