|
復(fù)制代碼 代碼如下:
function getarray_postgresql($arraystr)
{
$regx1 = '/^{(.*)}$/';
$regx2 = "http://"((////////|/////"|[^/"])+)/"|[^,]+/";
$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中讀取的數(shù)據(jù)都是字符串的,一般的數(shù)據(jù)還好處理,但是postgresql有一種數(shù)組型的數(shù)據(jù),而如果我們的數(shù)組是字符串的,前且,里面有逗號(hào)或斜線(xiàn)也是可能的,這就給我們讀取帶來(lái)了一定的麻煩,上面的函數(shù)是我?jiàn)^斗了幾個(gè)小時(shí)寫(xiě)出來(lái)的。盡可能的考慮到了斜線(xiàn),逗號(hào),引號(hào)的存在。
php技術(shù):PHP 讀取Postgresql中的數(shù)組,轉(zhuǎn)載需保留來(lái)源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。