Using UTF-8 charset with PHP - are mb functions required?

后端 未结 8 2009
不知归路
不知归路 2021-01-01 02:05

These past few days I\'ve been working toward converting my PHP code base from latin1 to UTF-8. I\'ve read the two main solutions are to either replace the single byte funct

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-01 02:32

    As soon as you're examining or modifying a multibyte string, you need to use a mb_* function. A very quick example which demonstrates why:

    $str = "abcžđščćöçefg";
    mb_internal_encoding("UTF-8");
    
    echo "strlen: ".strlen($str)."\n";
    echo "mb_strlen: ".mb_strlen($str)."\n";
    

    This prints out:

    strlen: 20
    mb_strlen: 13
    

提交回复
热议问题