0
我一直在尋找基於正則表達式來分割字符串,但我也有在保持我們分裂的文字興趣:使preg_split使用PREG_SPLIT_DELIM_CAPTURE
php > var_dump(preg_split("/(\^)/","category=Telecommunications & CATV^ORcategory!=ORtest^caused_byISEMPTY^EQ"), null, PREG_SPLIT_DELIM_CAPTURE);
array(4) {
[0]=> string(34) "category=Telecommunications & CATV"
[1]=> string(18) "ORcategory!=ORtest"
[2]=> string(16) "caused_byISEMPTY"
[3]=> string(2) "EQ"
}
NULL
int(2)
我不明白的是爲什麼我沒有收到數組如:
array(4) {
[0]=> "category=Telecommunications & CATV"
[1]=> "^"
[2]=> "ORcategory!=ORtest"
[3]=> "^"
[4]=> "caused_byISEMPTY"
[5]=> "^"
[6]=> "EQ"
}
此外,我怎麼會改變我的正則表達式匹配「^ OR」,也是「^」。我有麻煩了向後斷言如:
$regexp = "/(?<=\^)OR|\^/";
只是要清楚,這是)這是在錯誤的地方。因此,PREG_SPLIT_DELIM_CAPTURE並未作爲函數調用的一部分提交。 – 2010-10-11 21:15:13
我的歉意,我認爲這是一個很好的跡象表明現在是停止編碼的時候了。對不起浪費時間。 – Chris 2010-10-12 03:17:50