Safe to use strpos with UTF-8 strings?

前端 未结 2 837
时光取名叫无心
时光取名叫无心 2021-01-27 08:57

I have a bunch of strings with different charsets. The $charset variable contains the charset of the current string.

$content = iconv($charset, \'UT         


        
2条回答
  •  自闭症患者
    2021-01-27 09:44

    Functions like strlen() count bytes, not characters.

    See the notes in the PHP Manual for details:

    Note:

    strlen() returns the number of bytes rather than the number of characters in a string.

    use the mb_* functions if you're working with UTF-8, unless you have the php.ini setting mbstring.func_overload enabled to overload the standard strops(), strlen(), substr(), etc functions... then strlen() will count characters

提交回复
热议问题