多字节字符串
简介
虽然许多语言每个必要字符都能一对一映射到 8 比特(bit)的值,但也有好几种语言需要非常多的字符来书面通讯,以至于它们的编码范围不能仅仅包含在一个字节里(一个字节 Byte 由 8 比特 bit 构成。每一比特仅能包含两种不同的值: 1 或 0。所以,一字节仅能够表示 256 种不同的值,即 2 的八次方)。 开发多字节字符编码方案是为了在基于字节的常规编码系统中表达超过 256 个字符。
在你操作(trim、split、splice 等等)多字节编码的字符串的时候,由于在这种编码方案下,两个或多个连续字节可能只表达了一个字符,所以你需要使用专门的函数。 否则,当你将不能检测多字节字符串的函数应用到这个字符串的时候,它可能无法检测多字节字符的起始位置,并以乱码字符串结尾,基本丢失了它原来的意思。
mbstring 提供了针对多字节字符串的函数,能够帮你处理 PHP 中的多字节编码。
除此以外,mbstring 还能在可能的字符编码之间相互进行编码转换。
为了方便起见,mbstring 设计成了处理基于 Unicode 的编码,类似 UTF-8、UCS-2 及诸多单字节的编码(在 支持的编码 列出了)。
- 安装/配置
- 预定义常量
- 支持编码的摘要
- 日文字符多字节编码基础
- HTTP 输入和输出
- 支持的字符编码
- 函数重载功能
- PHP字符编码的要求
- 多字节字符串 函数
- mb_check_encoding — 检查字符串在指定的编码里是否有效
- mb_chr — 按 Unicode 码位值返回字符
- mb_convert_case — 对字符串进行大小写转换
- mb_convert_encoding — 转换字符串,从一个字符编码到另一个字符编码
- mb_convert_kana — Convert "kana" one from another ("zen-kaku", "han-kaku" and more)
- mb_convert_variables — 转换一个或多个变量的字符编码
- mb_decode_mimeheader — 解码 MIME 头字段中的字符串
- mb_decode_numericentity — 根据 HTML 数字字符串解码成字符
- mb_detect_encoding — 检测字符的编码
- mb_detect_order — 设置/获取 字符编码的检测顺序
- mb_encode_mimeheader — 为 MIME 头编码字符串
- mb_encode_numericentity — Encode character to HTML numeric string reference
- mb_encoding_aliases — 获取已知编码类型的别名
- mb_ereg — Regular expression match with multibyte support
- mb_ereg_match — Regular expression match for multibyte string
- mb_ereg_replace — Replace regular expression with multibyte support
- mb_ereg_replace_callback — Perform a regular expression search and replace with multibyte support using a callback
- mb_ereg_search — Multibyte regular expression match for predefined multibyte string
- mb_ereg_search_getpos — Returns start point for next regular expression match
- mb_ereg_search_getregs — Retrieve the result from the last multibyte regular expression match
- mb_ereg_search_init — Setup string and regular expression for a multibyte regular expression match
- mb_ereg_search_pos — Returns position and length of a matched part of the multibyte regular expression for a predefined multibyte string
- mb_ereg_search_regs — Returns the matched part of a multibyte regular expression
- mb_ereg_search_setpos — Set start point of next regular expression match
- mb_eregi — Regular expression match ignoring case with multibyte support
- mb_eregi_replace — Replace regular expression with multibyte support ignoring case
- mb_get_info — 获取 mbstring 的内部设置
- mb_http_input — 检测 HTTP 输入字符编码
- mb_http_output — 设置/获取 HTTP 输出字符编码
- mb_internal_encoding — 设置/获取内部字符编码
- mb_language — 设置/获取当前的语言
- mb_lcfirst — Make a string's first character lowercase
- mb_list_encodings — 返回所有支持编码的数组
- mb_ltrim — Strip whitespace (or other characters) from the beginning of a string
- mb_ord — 获取字符的 Unicode 码位值
- mb_output_handler — 在输出缓冲中转换字符编码的回调函数
- mb_parse_str — 解析 GET/POST/COOKIE 数据并设置全局变量
- mb_preferred_mime_name — 获取 MIME 字符串
- mb_regex_encoding — Set/Get character encoding for multibyte regex
- mb_regex_set_options — Set/Get the default options for mbregex functions
- mb_rtrim — Strip whitespace (or other characters) from the end of a string
- mb_scrub — Replace ill-formed byte sequences with the substitute character
- mb_send_mail — 发送编码过的邮件
- mb_split — 使用正则表达式分割多字节字符串
- mb_str_pad — Pad a multibyte string to a certain length with another multibyte string
- mb_str_split — 指定多字节字符串,返回其字符数组
- mb_strcut — 获取字符的一部分
- mb_strimwidth — 获取按指定宽度截断的字符串
- mb_stripos — 大小写不敏感地查找字符串在另一个字符串中首次出现的位置
- mb_stristr — 大小写不敏感地查找字符串在另一个字符串里的首次出现
- mb_strlen — 获取字符串的长度
- mb_strpos — 查找字符串在另一个字符串中首次出现的位置
- mb_strrchr — 查找指定字符在另一个字符串中最后一次的出现
- mb_strrichr — 大小写不敏感地查找指定字符在另一个字符串中最后一次的出现
- mb_strripos — 大小写不敏感地在字符串中查找一个字符串最后出现的位置
- mb_strrpos — 查找字符串在一个字符串中最后出现的位置
- mb_strstr — 查找字符串在另一个字符串里的首次出现
- mb_strtolower — 使字符串小写
- mb_strtoupper — 使字符串大写
- mb_strwidth — 返回字符串的宽度
- mb_substitute_character — 设置/获取替代字符
- mb_substr — 获取部分字符串
- mb_substr_count — 统计字符串出现的次数
- mb_trim — Strip whitespace (or other characters) from the beginning and end of a string
- mb_ucfirst — Make a string's first character uppercase
来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。
