我有函數將取代字符串前。 :微笑:帶有圖片標籤。跳過preg_replace,如果匹配字符串不在數組中
function out_emoj($str)
{
$emoj_array = array(
"cry", "grimacing", "joy","smiley","innocent", "wink", "flushed", "slight_smile",
"stuck_out_tongue_winking_eye", "relaxed", "crab","cat","expressionless", "pig", "rose", "cherry_blossom",
"sunny", "cloud_snow", "coffee","tea","grin", "ring", "crown", "nerd",
"heart_eyes", "kissing_heart", "sunglasses","scream","rage","disappointed","fearful","confused",
"dizzy_face", "zipper_mouth", "thermometer_face","sleeping","ghost","smiley_cat","smile_cat","joy_cat",
"heart_eyes_cat", "smirk_cat", "kissing_cat","scream_cat","crying_cat_face","pouting_cat","thumbsup","thumbsdown",
"angel", "dancer", "kimono","heart","purple_heart","sparkling_heart","heart_decoration","snowflake",
);
return preg_replace("/:(.*?):/", " <img width='22' src='".base_url('assets/img/emojiones/$1.png')."' alt='$1'> ", $str);
}
我想檢查匹配字符串是否在數組中,然後替換其他跳過。 例如:如果用戶輸入:notfound:函數將添加標籤與圖像不存在。我想先檢查「notfound」是否在數組中。
看看:'preg_replace_callback()' – Rizier123
爲什麼不使用簡單的循環?在這種情況下,Pregmatch總是矯枉過正。 – cpugourou