我有以下字符串:PHP正則表達式preg_match_all字符串
關鍵字|標題| HTTP://example.com/
我想用PHP函數
preg_match_all ($anchor, $key, $matches, PREG_SET_ORDER))
當前
$anchor='/([\w\W]*?)\|([\w\W]*)/';
我得到$ matches數組:
Array
(
[0] => Array
(
[0] => keyword|title|http://example.com/
[1] => keyword
[2] => title|http://example.com/
)
)
我想獲得
matches[1]=keyword
matches[2]=title
matches[3]=http://example.com
我會如何修改$錨實現這一目標?
你只需要在你的正則表達式中增加一個'\ |([\ w \ W] *?)''。 – mario 2011-04-12 21:12:33
謝謝,這工作。最終表達式:$ anchor ='/([\ w \ W] *?)\ |([\ w \ W] *?)\ |([\ w \ W] *)/'; – IberoMedia 2011-04-12 21:52:14