php substr() function with utf-8 leaves � marks at the end

前端 未结 7 1419
野的像风
野的像风 2020-11-27 05:32

Here is simple code



        
7条回答
  •  余生分开走
    2020-11-27 05:37

    If your strings may contain Unicode (multi-byte) characters and you don’t want to break these, replace substr with one of the following two, depending on what you want:

    Limit to 142 characters:

    mb_substr($var, 0, 142);
    

    Limit to 142 bytes:

    mb_strcut($var, 0, 142);
    

提交回复
热议问题