PHP 读取Postgresql中的数组_PHP教程

编辑Tag赚U币

推荐:php简单开启gzip压缩方法(zlib.output_compression)
网上的教程基本是你抄我来我抄他,不外乎加头加尾或者自构函数两种写法。实际上每个php页面都要去加代码——当然也可以include引用,不过总显得略微麻烦

复制代码 代码如下:www.mb5u.com

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有一种数组型的数据,而如果我们的数组是字符串的,前且,里面有逗号或斜线也是可能的,这就给我们读取带来了一定的麻烦,上面的函数是我奋斗了几个小时写出来的。尽可能的考虑到了斜线,逗号,引号的存在。

分享:做了CDN获取用户真实IP的函数代码(PHP与Asp设置方式)
asp取真实IP的代码,搭环境测试无代理、一级或多级代理的情况,可以正常获取

来源:模板无忧//所属分类:PHP教程/更新时间:2013-04-22
相关PHP教程