PHP 讀取Postgresql中的陣列

2022-03-21 20:02:20 字數 688 閱讀 3491

1

function getarray_postgresql($arraystr)2

$/';

4$regx2 = "/\"((\\\\\\\\|\\\\\"|[^\"])+)\"|[^,]+/";

5$regx3 = '/^[^"].*$|^"(.*)"$/';

6$match = null;7

preg_match( $regx1,$arraystr,$match);8

$str = $match[1];

9preg_match_all($regx2, $str,$match

);10

$items = $match[0];

11$array = array

();12

$count = count($items

);13

for($index = 0; $index

< $count;++$index)14

18return

$array

;19 }

在php從postgresql中讀取的資料都是字串的,一般的資料還好處理,但是postgresql有一種陣列型的資料,而如果我們的陣列是字串的,前且,裡面有逗號或斜線也是可能的,這就給我們讀取帶來了一定的麻煩,上面的函式是我奮鬥了幾個小時寫出來的。盡可能的考慮到了斜線,逗號,引號的存在。

php 使用pdo連線postgresql

有關pdo的使用可以參考 1 連線資料庫方法 function conn t catch pdoexception ex return db 2 使用示例 查詢user表使用者資訊 sql sprintf select from s where passport s and passwd s use...

php 讀取檔案

那如何讀取乙個檔案呢?我們先學乙個函式。int readfile string 檔名 linux類的讀了方式 readfile home paul test.txt windows類的讀取方式 readfile c boot.ini file get contents開啟檔案 上面的是單純打檔案就直...

php讀取csv指定行 PHP讀取csv檔案的內容

一次性讀取csv檔案內所有行的資料 file fopen windows 2011 s.csv r while data fgetcsv file 每次讀取csv裡面的一行內容 print r data 此為乙個陣列,要獲得每乙個資料,訪問陣列下標即可 goods list data print r...