正則表達式,可就是這樣,用"preg_match()
"的named subpattern: -
$a = array(
array(
'|174|September|2001|',
'|Pengantar=Hello!!!!',
'|Tema= Sami Mawon',
'|Tema_isi=meet you!!!',
'|Kutip=people',
'|Kutip_kitab=Efesus',
'|Kutip_pasal=4',
'|Kutip_ayat=28',
'|Tema_sumber=Kiriman dari Maurits albert ([email protected])',
'[[Kategori:e-humor 2001]]',
)
);
$pattern = '/(?<first>\w+)[:=](?<rest>[\d|\w|\s]+)/';
$matches = array();
foreach ($a as $_arrEach) {
foreach ($_arrEach as $_each) {
$result = preg_match($pattern, $_each, $matches[]);
}
}
echo "<pre>";
print_r($matches);
echo "</pre>";
你會發現,在數組鍵「first
」滿足您的要求。
上面會輸出: -
Array
(
[0] => Array
(
)
[1] => Array
(
[0] => Pengantar=Hello
[first] => Pengantar
[1] => Pengantar
[rest] => Hello
[2] => Hello
)
[2] => Array
(
[0] => Tema= Sami Mawon
[first] => Tema
[1] => Tema
[rest] => Sami Mawon
[2] => Sami Mawon
)
[3] => Array
(
[0] => Tema_isi=meet you
[first] => Tema_isi
[1] => Tema_isi
[rest] => meet you
[2] => meet you
)
[4] => Array
(
[0] => Kutip=people
[first] => Kutip
[1] => Kutip
[rest] => people
[2] => people
)
[5] => Array
(
[0] => Kutip_kitab=Efesus
[first] => Kutip_kitab
[1] => Kutip_kitab
[rest] => Efesus
[2] => Efesus
)
[6] => Array
(
[0] => Kutip_pasal=4
[first] => Kutip_pasal
[1] => Kutip_pasal
[rest] => 4
[2] => 4
)
[7] => Array
(
[0] => Kutip_ayat=28
[first] => Kutip_ayat
[1] => Kutip_ayat
[rest] => 28
[2] => 28
)
[8] => Array
(
[0] => Tema_sumber=Kiriman dari Maurits albert
[first] => Tema_sumber
[1] => Tema_sumber
[rest] => Kiriman dari Maurits albert
[2] => Kiriman dari Maurits albert
)
[9] => Array
(
[0] => Kategori:e
[first] => Kategori
[1] => Kategori
[rest] => e
[2] => e
)
)
希望它能幫助。
請說明您想要的值以及匹配這些值的條件。 – salathe 2012-01-12 09:16:36