PHP 读取Postgresql中的数组

代码如下:
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;
}

PHP从postgresql中读取的数据都是字符串的,一般的数据还好处理,但是postgresql有一种数组型的数据,而如果我们的数组是字符串的,前且,里面有逗号或斜线也是可能的,这就给我们读取带来了一定的麻烦,上面的函数是我奋斗了几个小时写出来的。尽可能的考虑到了斜线,逗号,引号的存在。

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...