问题
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