如何清理一串类似以下情况的推文
2013 Porsche Cayman First Drive #car # news @ watchthis in Your City
我想清除标签(#car#news)和 twitter 用户名(在本例中为 @watchthis)
像这样 :
2013 保时捷 Cayman 首次在您的城市驾驶
使用正则表达式 (PHP)
谢谢你
@bimoheryprabowo
试试这个代码:
echo preg_replace('/(?:#\s*[\w\d]+|@\s*[\w\d]+)/', '', $string);
尝试这个
$text='2013 Porsche Cayman First Drive # car # news @ watchthis in Your City';
echo preg_replace('/(@\s([\\d\\w]+))|(#\s([\\d\\w]+))/', ' ', $text);
OR
echo preg_replace('/((@|#)\s)([\\d\\w]+)/', ' ', $text);