PHP reads the array in Postgresql

  • 2020-06-01 08:24:30
  • OfStack


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;
 }

The data read from the PHP postgresql are strings, 1 well data processing, but postgresql have 1 kind of array data type, and if we are string array, and before, there is a comma or slash is possible, it can give us read 1 set of trouble, the above function is written for a few hours I struggle. Consider slashes, commas, and quotation marks whenever possible.


Related articles: