$str = '@中肖 @尖 困@地s_3法 @在有 @ ';
preg_match_all('/@+\s/', $str, $matchs);
想得到@与空格之间的xxx(可为中文与英文,下划线等符号)
我这样写是错了。求大侠帮手。谢谢了!当然有其他方法可以得到数组(@中肖,@尖,@地s_3法,@在有)也行,求赐教!
preg_match_all('/@+\s/', $str, $matchs);
想得到@与空格之间的xxx(可为中文与英文,下划线等符号)
我这样写是错了。求大侠帮手。谢谢了!当然有其他方法可以得到数组(@中肖,@尖,@地s_3法,@在有)也行,求赐教!
preg_match_all("/@\S{1,}\s/", $str, $matchs);\S (大写) 表示所有非空白字符, 后跟 {1,} 表示必须至少有一个匹配字节
Array
(
[0] => @中肖
[1] => @尖
[2] => @地s_3法
[3] => @在有
)
[[email protected] php_project]$ cat main.php
<?php
$content = "@中肖 @尖 困@地s_3法 @在有 @ ";
$n_match = preg_match_all('/@.* /U', $content, $matches);
if ($n_match) {
$res = array_filter($matches[0], function($item){return trim($item, "@ ");});
print_r($res);
}
?>
preg_match_all('/@\S{1,}/', $str, $matchs);for ($i = 0; $i < count($matchs[0]); $i++) {
echo "[".$i."] => ".$matchs[0][$i]."<br />";
}
感谢谢楼上二位的帮助!
qq120848369
$res = array_filter($matches[0], function($item){return trim($item, "@ ");});
这句运行的时候出错了。谢谢dream1206的回答与分析!