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

后端 未结 8 2012
不知归路
不知归路 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条回答
  • You can use this http://php.net/manual/en/mbstring.overload.php setting in php.ini file, so you don't need to change you code.

    But be careful, because not all string function will be automatically changed. This is one: http://php.net/manual/en/function.substr-replace.php

    0 讨论(0)
  • 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
    
    0 讨论(0)
提交回复
热议问题