-2
之前,我有這個字符串獲取字符串後一切@和空白
$string="@smn and @someone are web developers"
,我想@smn
和@someone
從string.How我能做到這一點?
之前,我有這個字符串獲取字符串後一切@和空白
$string="@smn and @someone are web developers"
,我想@smn
和@someone
從string.How我能做到這一點?
使用preg_match_all
用正則表達式/(?<!\w)@\w+/
$string="@smn and @someone are web developers";
preg_match_all('/(?<!\w)@\w+/',$string,$matches);
print_r($matches[0]);
當我嘗試呼應它works.But當我嘗試將其插入到數據庫它說:「Array對字符串的轉換」和插件組.Here是我的查詢$ query = $ con> query(「INSERT INTO notifications(Post_id,Username,Initiator,type,'Date')VALUES('$ IdU','$ matches [0]','$ Name' ,'提及',NOW())「); – user6612671
用它作爲'$ matches [0] [0]'或'$ matches [0] [1]'它會返回值 – Saty
謝謝!有效 – user6612671