用户输入看不见的特殊符号,导致UI错乱

贵贵的博客 ( http://blog.linuxphp.org/ ) : 今天客户端反馈一个问题用户说的话顺序都反了, 查了下好像昵称里多了什么特殊字符   数据库查询,没有什么不同:   select * from user where id=587618\G *************************** 1. row ***************************              id: 587618            nick: 49‭‏筱喜   复制结果到vim里 select * from user where id=587618\G *************************** 1. row ***************************              id: 587618            nick: 49<202d><200f>筱喜   这个"<202d><200f>"是什么鬼, 在网页里用F12查看源代码 是 这样的 "nick: 49&#8237;&rlm;筱喜"

搜索  &#8237 得到此解读:https://en.wikipedia.org/wiki/Right-to-left_mark

 

后面在这里找到了用PHP怎么替换

https://github.com/Pasvaz/laravel-skeleton/blob/master/application/libraries/localizeddate.php

整理一下,方便使用

function stripLRMRLM($inputText)
    {
        // UTF8 control codes affecting the BiDirectional algorithm (see http://www.unicode.org/reports/tr9/)
        $CH_UTF8_LRM = "\xE2\x80\x8E"; // U+200E  (Left to Right mark:  zero-width character with LTR directionality)
        $CH_UTF8_RLM = "\xE2\x80\x8F"; // U+200F  (Right to Left mark:  zero-width character with RTL directionality)
        $CH_UTF8_LRO = "\xE2\x80\xAD"; // U+202D  (Left to Right override: force everything following to LTR mode)
        $CH_UTF8_RLO = "\xE2\x80\xAE"; // U+202E  (Right to Left override: force everything following to RTL mode)
        $CH_UTF8_LRE = "\xE2\x80\xAA"; // U+202A  (Left to Right embedding: treat everything following as LTR text)
        $CH_UTF8_RLE = "\xE2\x80\xAB"; // U+202B  (Right to Left embedding: treat everything following as RTL text)
        $CH_UTF8_PDF = "\xE2\x80\xAC"; // U+202C  (Pop directional formatting: restore state prior to last LRO, RLO, LRE, RLE)

        $notvalid=array($CH_UTF8_LRM, $CH_UTF8_RLM, $CH_UTF8_LRO, $CH_UTF8_RLO, $CH_UTF8_LRE, $CH_UTF8_RLE, $CH_UTF8_PDF, "&lrm;", "&rlm;", "&LRM;", "&RLM;");
        return str_replace($notvalid, "", $inputText);
    }

 

文章来源:

Author:linuxphp@qq.com(keminar)
link:http://blog.linuxphp.org/archives/1657/