使用单引号。我不能强调这一点。也是$
字符串结尾的元字符。我怀疑你在分裂时想要这个。
您可能希望使用更多类似的东西preg_match_all
进行匹配:
$matches = array();
preg_match_all('#(.*?)\s-\s(\d{1,2})\s*#', $item->title, $matches);
var_dump($matches);
产生:
array(3) {
[0]=>
array(3) {
[0]=>
string(17) "a few words - 25 "
[1]=>
string(22) "some more - words - 7 "
[2]=>
string(29) "another - set of - words - 13"
}
[1]=>
array(3) {
[0]=>
string(11) "a few words"
[1]=>
string(17) "some more - words"
[2]=>
string(24) "another - set of - words"
}
[2]=>
array(3) {
[0]=>
string(2) "25"
[1]=>
string(1) "7"
[2]=>
string(2) "13"
}
}
认为您可以从该结构中收集到您需要的信息?