$check = array("this", "that", "to be", "not to be");
$yes = $no = array();
我試圖檢查,是每個項目的數組$check
包含文本「是」。支票是可變的有這個文字
如果是,則將其添加到$yes
,否則將添加到$no
。
似乎我必須使用一個正則表達式,你能幫我寫作嗎?
$check = array("this", "that", "to be", "not to be");
$yes = $no = array();
我試圖檢查,是每個項目的數組$check
包含文本「是」。支票是可變的有這個文字
如果是,則將其添加到$yes
,否則將添加到$no
。
似乎我必須使用一個正則表達式,你能幫我寫作嗎?
如果你想尋找完整的單詞be
而不是be
作爲一個子,你可以使用:
$check = array("this", "that", "to be", "not to be");
$yes = $no = array();
foreach($check as $v) {
if(preg_match('/\bbe\b/',$v)) {
$yes[] = $v;
} else {
$no[] = $v;
}
}
它有沒有待字是或將像'相信'這樣的詞會被接受嗎? – Belinda 2011-03-21 17:40:58