具体如下:
<?php
$str = 'A10:aaa1aaa。A42:aaa2aaa。A3-8:aaa3aaa。.A9:aaa4aaa。';
$regex = "/(A\d+)(-\d+)*(:|:)/";
$keywords = preg_split($regex, $str);
var_dump($keywords);
?>
期待返回:
array
0 => string 'A10:aaa1aaa。'
1 => string 'A42:aaa2aaa。'
2 => string 'A3-8:aaa3aaa。.'
3 => string 'A9:aaa4aaa。'
却返回:
array
0 => string '' (length=0)
1 => string 'aaa1aaa。' (length=9)
2 => string 'aaa2aaa。' (length=9)
3 => string 'aaa3aaa。.' (length=10)
4 => string 'aaa4aaa。' (length=9)
怎么解决呢?
'A10:aaa1aaa。A42:aaa2aaa。A3-8:aaa3aaa。.A9:aaa4aaa。',这里边的aaa1aaa。其实代表大段的中文文字,在数据库中是放在一个字段的,显示时又想分段显示,以 A... 为分段标记,同时这分段标记又也要显示出来。
<?php
$str = 'A10:aaa1aaaã A42ï¼aaa2aaaã A3-8:aaa3aaaã. A9:aaa4aaaã';//åå¥åé´å äºä¸ä¸ªç©ºæ ¼
$arr = explode(" ",$str);//è¿æ¯ä»¥ç©ºæ ¼ä¸ºåå²ç¬¦ï¼ä¹å¯ä»¥ç¨å ¶ä»çååé符ï¼æ¯å¦åå·ãéå·
print_r ($arr);
?>
$str = 'A10:aaa1aaaã A42ï¼aaa2aaaã A3-8:aaa3aaaã. A9:aaa4aaaã';//åå¥åé´å äºä¸ä¸ªç©ºæ ¼
$arr = explode(" ",$str);//è¿æ¯ä»¥ç©ºæ ¼ä¸ºåå²ç¬¦ï¼ä¹å¯ä»¥ç¨å ¶ä»çååé符ï¼æ¯å¦åå·ãéå·
print_r ($arr);
?>
温馨提示:答案为网友推荐,仅供参考