使用 PHP 检测纯文本中的表情符号

Detect emoji in plain text using PHP

我想更改以下形式的表达式:

[E-01] - [E-02] - [E-03] - [E-04] ... 

<img src = "E-XX.png">

我该怎么做?

输入

$message = "Hello [E-02] World [E-01]";

期望的输出

Hello <img src="E-02.png"> World <img src="E-01.png">
function emoji($message){
            for($e=1; $e <= 60; $e++){
                $e    = (($e < 10) ? '0' . $e : $e);
                $name = 'E-' . $e;
                $message = str_replace('[' . $name . ']', ' <img src="/assets/images/emoji/' . $name. '.png" height="20" width="20" /> ', $message);
            }
            return $message;
        }

Preg_replace是你的朋友:

$message = "Hello [E-02] World [E-01]";
$replaced = preg_replace('/\[(E-\d\d)\]/', '<img src="/assets/images/emoji/.png" height="20" width="20" />', $message);
echo $replaced;

输出:

Hello <img src="/assets/images/emoji/E-02.png" height="20" width="20" /> World <img src="/assets/images/emoji/E-01.png" height="20" width="20" />