时间:2021-07-01 10:21:17 帮助过:21人阅读
$str='[#微笑][#大哭][#色]';preg_match_all('/\[#(.+?)\]/',$str,$m);echo '';
我的$str里面的表情数量是不定的,而且还会有其他非表情的字符
如:$str=我来啦!![#微笑][#微笑]么么~~[#色] 变成:我来啦!!么么~~
网上看了个例子:$str = preg_replace ( "[\[#([0-9]*)\]]", "", $str );
但是这个只能替换[#1][#22]这种 如果是中文的 要怎么改呢?正则一点都不懂啊
$str='af d [#微笑]adfaf[#大哭]asdfasd[#色]asdfaf';$new = preg_replace('/\[\#(.+?)\]/', "", $str);var_dump($new);
$str='af d [#微笑]adfaf[#大哭]asdfasd[#色]asdfaf';$new = preg_replace('/\[\#(.+?)\]/', "", $str);var_dump($new);
$str = "[#微笑][#大哭][#色]";
$pattern = "/\[#([\s\S]*)\]\s*\[#([\s\S]*)\]\s*\[#([\s\S]*)\]\s*/";
preg_match_all($pattern,$str,$match);
$new_str = preg_replace($pattern,'',$str);
echo $new_str;