2012-08-12 56 views
0

我有這個大表情符號的列表,我已經下載,謝天謝地他們帶着表情符號,所以我不必讓所有這些(如smile:):-))。下面是它在文件格式的示例塊。PHP解析Pidgin表情符號包

smile.png   :)  :-) 
smile-big.png  :D  :d :-D :-d 
wink.png   ;)  ;-) 
shock.png   :-O  :-o :O :o 
tongue.png   :P  :p :-P :-p 
glasses-cool.png (H)  (h) 
angry.png   :@  :[email protected] 
embarrassed.png  :$  :-$ 
confused.png  :S  :s :-S :-s 
sad.png    :(  :-(
crying.png   :'(
neutral.png   :|  :-| 
devil.png   (6) 
angel.png   (A)  (a) 
love.png   (L)  (l) 
love-over.png  (U)  (u) 
msn.png    (M)  (m) 
cat.png    (@) 
dog.png    (&) 
moon.png   (S) 
star.png   (*) 
film.png   (~) 

但是,沒有修改此列表或以任何方式重新鍵入它,我就可以要經過串並替換爲符號的發生圖像標籤纏繞圖像名稱。因此,與表情定義爲字符串塊,有沒有將工作像convert_emotes($text, $emote_definitions);,並打開

Hello world :) :D this is a heart emote: (L) and here's a dog (&) 

Hello world <img src="smile.png" /> <img src="smile-big.png" /> this is a heart emote: <img src="love.png" /> and here's a dog <img src="dog.png" /> 

任何幫助是非常讚賞的任何功能!

回答

1

不是一個很好的代碼,但它可能工作:

<?php 
$patterns = array(); 
$replacements = array(); 

foreach (split("\n", file_get_contents("file")) as $line){ 
    $l = preg_split("/\s+/",$line); 
    for($i = 1; $i < count($l); $i++){ 
     $patterns[] = $l[$i]; 
     $replacements[] = "<img src='{$l[0]}' />"; 
    } 
} 


echo str_replace($patterns, $replacements, "Hello world :) :D this is a heart emote: (L) and here's a dog (&)"); 
+0

是的!你真了不起 – 2012-08-13 03:44:41