2016-07-20 23 views

回答

0

使用preg_match_all用正則表達式/(?<!\w)@\w+/

$string="@smn and @someone are web developers"; 
preg_match_all('/(?<!\w)@\w+/',$string,$matches); 
print_r($matches[0]); 

DEMO

+0

當我嘗試呼應它works.But當我嘗試將其插入到數據庫它說:「Array對字符串的轉換」和插件組.Here是我的查詢$ query = $ con> query(「INSERT INTO notifications(Post_id,Username,Initiator,type,'Date')VALUES('$ IdU','$ matches [0]','$ Name' ,'提及',NOW())「); – user6612671

+0

用它作爲'$ matches [0] [0]'或'$ matches [0] [1]'它會返回值 – Saty

+0

謝謝!有效 – user6612671