gpt4 book ai didi

php - str_replace 表情符号 Laravel

转载 作者:搜寻专家 更新时间:2023-10-31 21:05:51 27 4
gpt4 key购买 nike

我想用表情符号替换文本。问题是我不知道如何更换很多。此时我有这段代码正在运行:

<p>
{!! str_replace(':D', '<img src="/emoticons/grin.png" alt="">', $post->content) !!}
</p>

所以当我写“:D”时,表情符号工作正常,但我不知道如何添加更多的表情符号。

感谢任何帮助。

最佳答案

您可以将其替换为数组:

$emotions = array(":D", ":)", ":(");
$images = array("<img src=\"/emoticons/grin.png\" alt=\"\">", "<img src=\"/emoticons/img2.png\" alt=\"\">", "<img src=\"/emoticons/img3.png\" alt=\"\">");
//Then replace
<p>{!! str_replace($emotions, $images, $post->content) !!}</p>

请注意:$emotions 和 $images 必须按顺序配对。您可以在 http://php.net/manual/en/function.str-replace.php 了解 str_replace

关于php - str_replace 表情符号 Laravel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32547555/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com