>  기사  >  백엔드 개발  >  PHP 读取Postgresql中的数组_PHP教程

PHP 读取Postgresql中的数组_PHP教程

WBOY
WBOY원래의
2016-07-21 15:11:41866검색

复制代码 代码如下:

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      {
         preg_match($regx3, $items[$index],$match);
         $array[$index]=end($match);
     }
     return $array;
 }

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

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/326853.htmlTechArticle复制代码 代码如下: function getarray_postgresql($arraystr) { $regx1 = '/^{(.*)}$/'; $regx2 = "/\"((\\\\\\\\|\\\\\"|[^\"])+)\"|[^,]+/"; $regx3 = '/^[^"].*$|^"(.*)"$/'; $matc...
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.