如何獲得條件前綴[+
和後綴+]
的字符串部分,然後將其全部返回到數組中?如果使用條件前綴[+和後綴+]獲取字符串的一部分
例如:
$string = 'Lorem [+text+] Color Amet, [+me+] The magic who [+do+] this template';
// function to get require
function getStack ($string, $prefix='[+', $suffix='+]') {
// how to get get result like this?
$result = array('text', 'me', 'do'); // get all the string inside [+ +]
return $result;
}
許多感謝...
這應該是一個相當簡單的正則表達式。像'preg_match_all(「/\\[\\+(.*?)\\+\\]/」);'然後得到結果的組1。 – Alxandr 2010-11-14 05:20:06