Convert keyboard emoticons into custom png and vice versa

和自甴很熟 提交于 2019-12-20 04:57:25

问题


Now this is a straight and simple question.

How can I achieve these two things.

FIRST

Input - hey I'm smiling 😁

Output - hey I'm smiling <span class ="smile"></span>

And vice versa.

SECOND

Input - hey I'm smiling :smile:

Output - hey I'm smiling 😁

Now I know the words extraction part. I just don't know in what form keyboard emoticons are?

For First.

I know this can be achieved by checking each word and using switch-case to check. But what goes inside the case statements?

For second

This one has same problem I can use :smile: in switch-case. But what should I replace the :smile: with to get the keyboard emoticon?

I know this has to do with some unicode characters but since I wasn't sure I came here in a hope for solution.

P. S - I am using php in server side.


回答1:


Try str_replace.

First:

<?php
$string = "hey I'm smiling 😁";
echo str_replace("😁", "<span class =\"smile\"></span>", $string);
?>

Second:

<?php
$string = "hey I'm smiling :smile:";
echo str_replace(":smile:", "😁", $string);
?>


来源:https://stackoverflow.com/questions/34549007/convert-keyboard-emoticons-into-custom-png-and-vice-versa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!