开发者

PHP substr and strlen alternative

开发者 https://www.devze.com 2022-12-22 05:35 出处:网络
I heard that in PHP there are some alternatives for the functions substr() and strlen() which handles safer bits. Is this 开发者_运维百科true and if it is then what are those functions? I heard that i

I heard that in PHP there are some alternatives for the functions substr() and strlen() which handles safer bits. Is this 开发者_运维百科true and if it is then what are those functions? I heard that it is based on the function strcmp() but I don't see directly how can I use it.


The functions are prefixed with mb_. See here: http://php.net/manual/en/ref.mbstring.php

From PHP's Multibyte String extension's introduction:

mbstring provides multibyte specific string functions that help you deal with multibyte encodings in PHP. In addition to that, mbstring handles character encoding conversion between the possible encoding pairs. mbstring is designed to handle Unicode-based encodings such as UTF-8 and UCS-2 and many single-byte encodings for convenience.


Maybe you mean safe for multibyte character encoding like UTF-8. Because substr and strlen are not safe for multibyte encodings. They count each character as one byte. But the multibyte string function take that into account.

0

精彩评论

暂无评论...
验证码 换一张
取 消