【问题标题】:Convert emoji into custom images [duplicate]将表情符号转换为自定义图像[重复]
【发布时间】:2015-12-31 21:38:32
【问题描述】:

输入 - 嘿,我在微笑 ????

输出 - 嘿,我在微笑<span class ="smile"></span>

代码

$emoticons = array('????' =>'<span class ="smile"></span>') ;
$str = strtr($str, $emoticons) ;

我不能使用str_replace,因为$emoticons 数组中有多个元素。

上面的代码不起作用,输入和输出保持不变。

【问题讨论】:

  • 你的输入字符串是 UTF-8 编码的吗?
  • 什么?我不确定。它取自mysql数据库。
  • 您必须确保输入的编码与源代码中使用的编码相匹配。
  • 这不仅与 OP 的另一个问题 stackoverflow.com/questions/34549007/… 略有不同,而且一开始就没有问题。此外,同一用户解决了这两个问题。

标签: php string utf-8 utf emoticons


【解决方案1】:

这对我有用:

<?php
$str = "hey I'm smiling ? and I'm crying ? ?"; // input
$emoticons = array('?' =>'<span class="smile"></span>','?' =>'<span class="cry"></span>') ; // array of emoticons and spans
$output = strtr($str, $emoticons); // change emoticons from array to spans from array
echo $output; // print it
?>

【讨论】:

  • 现在可以使用了!我发布这个问题不是最后一天。很奇怪。
猜你喜欢
  • 2020-07-05
  • 2019-12-25
  • 2019-07-11
  • 2015-02-20
  • 2021-10-18
  • 1970-01-01
  • 2019-01-10
  • 2014-10-04
  • 1970-01-01
相关资源
最近更新 更多