PHP reads array in Postgresql_PHP tutorial

WBOY
Release: 2016-07-21 15:11:41
Original
852 people have browsed it

Copy code The code is as follows:

function getarray_postgresql($arraystr)
{
$regx1 = '/ ^{(.*)}$/';
$regx2 = "/"((\\\\|\\"|[^"])+)"|[^,]+/";
$regx3 = '/^[^"].*$|^"(.*)"$/';
$match = null;
preg_match($regx1,$arraystr,$match);
$str = $match[1];
preg_match_all($regx2, $str,$match);
$items = $match[0];
$array = array();
$count = count($items);
for($index = 0; $index < $count;++$index)
{
preg_match($regx3, $items[$index] ,$match);
$array[$index]=end($match);
}
return $array;
}

in PHP from postgresql The data read are all strings, and general data is easy to process, but postgresql has an array type of data, and if our array is a string, it is possible that there are commas or slashes in it. This This brings us some trouble in reading. I struggled for several hours to write the function above, taking into account the existence of slashes, commas, and quotation marks as much as possible.

http://www.bkjia.com/PHPjc/326853.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326853.htmlTechArticleCopy the code The code is as follows: function getarray_postgresql($arraystr) { $regx1 = '/^{(.*)} $/'; $regx2 = "/"((\\\\|\\"|[^"])+)"|[^,]+/"; $regx3 = '/^[^"].* $|^"(.*)"$/'; $matc...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!