手机
当前位置:查字典教程网 >编程开发 >php教程 >PHP 读取Postgresql中的数组
PHP 读取Postgresql中的数组
摘要:复制代码代码如下:functiongetarray_postgresql($arraystr){$regx1='/^{(.*)}$/';$r...

复制代码 代码如下:

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

【PHP 读取Postgresql中的数组】相关文章:

PHP中的魔术方法总结和使用实例

PHP调用三种数据库的方法(1)

学习使用PHP数组

PHP中预定义的6种接口介绍

php获取网页上所有链接的方法

PHP5的XML新特性

php从文件夹随机读取文件的方法

PHP获取文件行数的方法

GD输出汉字的函数的分析

PHP IDE PHPStorm配置支持友好Laravel代码提示方法

精品推荐
分类导航