In this code, when I use ":-)" emoji, I do not see it in the output.
But when "1f60a" or "1f60c" or "e252" emoji is used, what is the problem?
& lt ;? Php $ emoji_url = "http://coremobile.ir/images_smileys"; $ Emoji_style = ""; $ Emoji_code = Array (":-)", "1f60a", "1f60c", "e252"); $ Emoji_img = array ('& lt; img src =' '. $ Emoji_url.' / 1f60a.png ''. $ Emoji_style. '& Gt;', '& lt; img src = "'. $ Emoji_url. '/ 1f60a.png "$ .imoji_style. '& Gt;', '& lt; img src ="'. $ Emoji_url. '/ 1f60c.png "' $ emoji_style. '& Gt;', '& lt; img src = "$ .imoji_url. '/ E252.png' '. $ Emoji_style.' & Gt; '); $ Ret =' This test :-) 1f60a '; $ Ret = str_replace ($ emoji_code, $ emoji_img, $ ret) ; Echo $ ret?; & Gt;
This should work for you: />
(just use instead, so that it does not go through the string multiple times)
$ ret = strtr ($ ret, array_combine ($ emoji_code, $ emoji_img)) ;
Output:
This test
No one else has done the work, because it takes the place of every match for the first replacement and then the second and so on.
0 replaced:
This test :-) 1f60a // ^ ^ match
ago changed:
this test & lt; Img src = "http://coremobile.ir/images_smileys/1f60a.png" & gt; 1f60a // ^^^^^ Match ^ ^^^^ Match
Second place given:
This test
No comments:
Post a Comment