源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

PHP 读取Postgresql中的数组

  • 时间:2020-08-28 01:38 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:PHP 读取Postgresql中的数组
[u]复制代码[/u] 代码如下:
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有一种数组型的数据,而如果我们的数组是字符串的,前且,里面有逗号或斜线也是可能的,这就给我们读取带来了一定的麻烦,上面的函数是我奋斗了几个小时写出来的。尽可能的考虑到了斜线,逗号,引号的存在。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部