如何获得条件前缀[+
和后缀+]
的字符串部分,然后将其全部返回到数组中?如果使用条件前缀[+和后缀+]获取字符串的一部分
例如:
$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