0
我想從字符串中獲取法庭名稱。但是我有找到它的問題。一般而言,它位於方括號內的第一次出現,但可能位於第二次出現。所以,我試圖通過數組來循環檢查法院名稱,如果不匹配任何法院名稱,則打印第二次出現。這裏是代碼:如何從PHP中的字符串中獲取正確的法院名稱
$string='<b>Yara
Pilbara Fertilisers Pty Ltd [formerly known as Burrup Fertilisers Pty Ltd] v
Oswal (No. 8)</b> (FCA) - cross-vesting - Federal Court
proceedings transferred to Supreme Court of Victoria';
preg_match_all('/\(([^\)]*)\)/', $string, $matches);
$all_courts=array("HCA","FCAFC","FCA","NSWCA","NSWSC","VCA","QCA","QSC","SASCFC","SASC","TSCA","TSC","WASCA","WASC","ACTCA","ACTSC","NTCA","NTSC");
$court_name=$matches[1][0];
for($i=0;$i<count($all_courts);$i++)
{
if($all_courts[$i]!=$court_name)
{
$court_name=$matches[1][1];
}
}
echo $court_name;
真棒,bobdye ..這是我想要的東西..感謝了很多 – floCoder 2015-02-11 00:41:56
喜,也可我得到的指數沒有。的匹配位置? – floCoder 2015-02-12 01:11:25
$ match = array_search($ court_name,$ all_courts)會給你匹配的索引。 – bobdye 2015-02-12 14:58:09