小伙伴们有遇到php解析特殊符号情况吗 有吧 是不是有时候解析可以了 突然又不不好使了呢  听司令给你们解析一下

php将特殊符号如笑脸等表情存到数据库 代码如下:

public function setEmo($str)
   {
$result = preg_replace_callback('/[\xf0-\xf7].{3}/',function($r){ return '@E' . base64_encode($r[0]);}, $str);
$this->assign('result',$result);
}

从数据库取出如下:

 public function getEmo($str)
{ $result = preg_replace_callback('/@E(.{6}==)/',function($r){return base64_decode($r[1]);}, $str); $this->assign('result',$result); }

 目前特殊字符已经被我们用php搞定 接下来页面部分 即html如下:

<div>{$result}</div> 此时正常显示

 但是若在此div加一些加粗属性 如下:

<div><b>{$result}</b></div>
<div style='font-size:bold;'>{$result}</div>

此时就不好用了  所以友情提示一下小伙伴们 解析表情符号后莫要用加粗属性给页面  如果对您有帮助 请点赞!!!

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-06
  • 2021-09-18
  • 2021-04-17
  • 2021-10-06
  • 2022-12-23
  • 2021-09-14
猜你喜欢
  • 2021-11-16
  • 2021-12-12
  • 2021-05-10
  • 2021-10-10
  • 2021-08-20
  • 2021-12-24
  • 2022-01-06
相关资源
相似解决方案