我想以以下形式更改表达式:[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">
2 回答
蛊毒传说
TA贡献1895条经验 获得超3个赞
Preg_replace是您的朋友:
$message = "Hello [E-02] World [E-01]";
$replaced = preg_replace('/\[(E-\d\d)\]/', '<img src="/assets/images/emoji/$1.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" />
- 2 回答
- 0 关注
- 208 浏览
添加回答
举报
0/150
提交
取消