<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/refs.international.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'book.mbstring.php',
    1 => '多字节字符串',
    2 => '多字节字符串',
  ),
  'up' => 
  array (
    0 => 'refs.international.php',
    1 => '国际化与字符编码支持',
  ),
  'prev' => 
  array (
    0 => 'function.intl-is-failure.php',
    1 => 'intl_is_failure',
  ),
  'next' => 
  array (
    0 => 'mbstring.setup.php',
    1 => '安装/配置',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'reference/mbstring/book.xml',
  ),
  'history' => 
  array (
  ),
  'extra_header_links' => 
  array (
    'rel' => 'alternate',
    'href' => '/manual/en/feeds/book.mbstring.atom',
    'type' => 'application/atom+xml',
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="book.mbstring" class="book">
 
 <h1 class="title">多字节字符串</h1> 
 
 
 <div id="intro.mbstring" class="preface">
  <h1 class="title">简介</h1>
  <p class="para">
   虽然许多语言每个必要字符都能一对一映射到 8 比特（bit）的值，但也有好几种语言需要非常多的字符来书面通讯，以至于它们的编码范围不能仅仅包含在一个字节里（一个字节 Byte 由 8 比特 bit 构成。每一比特仅能包含两种不同的值： 1 或 0。所以，一字节仅能够表示 256 种不同的值，即 2 的八次方）。
   开发多字节字符编码方案是为了在基于字节的常规编码系统中表达超过 256 个字符。
  </p>
  <p class="para">
   在你操作（trim、split、splice 等等）多字节编码的字符串的时候，由于在这种编码方案下，两个或多个连续字节可能只表达了一个字符，所以你需要使用专门的函数。
   否则，当你将不能检测多字节字符串的函数应用到这个字符串的时候，它可能无法检测多字节字符的起始位置，并以乱码字符串结尾，基本丢失了它原来的意思。
  </p>
  <p class="para">
   <code class="literal">mbstring</code> 提供了针对多字节字符串的函数，能够帮你处理 PHP 中的多字节编码。
   除此以外，<code class="literal">mbstring</code> 还能在可能的字符编码之间相互进行编码转换。
   为了方便起见，<code class="literal">mbstring</code> 设计成了处理基于 Unicode 的编码，类似 UTF-8、UCS-2 及诸多单字节的编码（在 <a href="mbstring.supported-encodings.php" class="link">支持的编码</a> 列出了）。
  </p>
 </div>
 
 
 








 







 


 



 







 









 





 








 









 




 





<ul class="chunklist chunklist_book"><li><a href="mbstring.setup.php">安装/配置</a><ul class="chunklist chunklist_book chunklist_children"><li><a href="mbstring.installation.php">安装</a></li><li><a href="mbstring.configuration.php">运行时配置</a></li></ul></li><li><a href="mbstring.constants.php">预定义常量</a></li><li><a href="mbstring.encodings.php">支持编码的摘要</a></li><li><a href="mbstring.ja-basic.php">日文字符多字节编码基础</a></li><li><a href="mbstring.http.php">HTTP 输入和输出</a></li><li><a href="mbstring.supported-encodings.php">支持的字符编码</a></li><li><a href="mbstring.overload.php">函数重载功能</a></li><li><a href="mbstring.php4.req.php">PHP字符编码的要求</a></li><li><a href="ref.mbstring.php">多字节字符串 函数</a><ul class="chunklist chunklist_book chunklist_children"><li><a href="function.mb-check-encoding.php">mb_check_encoding</a> — 检查字符串在指定的编码里是否有效</li><li><a href="function.mb-chr.php">mb_chr</a> — 按 Unicode 码位值返回字符</li><li><a href="function.mb-convert-case.php">mb_convert_case</a> — 对字符串进行大小写转换</li><li><a href="function.mb-convert-encoding.php">mb_convert_encoding</a> — 转换字符串，从一个字符编码到另一个字符编码</li><li><a href="function.mb-convert-kana.php">mb_convert_kana</a> — Convert &quot;kana&quot; one from another (&quot;zen-kaku&quot;, &quot;han-kaku&quot; and more)</li><li><a href="function.mb-convert-variables.php">mb_convert_variables</a> — 转换一个或多个变量的字符编码</li><li><a href="function.mb-decode-mimeheader.php">mb_decode_mimeheader</a> — 解码 MIME 头字段中的字符串</li><li><a href="function.mb-decode-numericentity.php">mb_decode_numericentity</a> — 根据 HTML 数字字符串解码成字符</li><li><a href="function.mb-detect-encoding.php">mb_detect_encoding</a> — 检测字符的编码</li><li><a href="function.mb-detect-order.php">mb_detect_order</a> — 设置/获取 字符编码的检测顺序</li><li><a href="function.mb-encode-mimeheader.php">mb_encode_mimeheader</a> — 为 MIME 头编码字符串</li><li><a href="function.mb-encode-numericentity.php">mb_encode_numericentity</a> — Encode character to HTML numeric string reference</li><li><a href="function.mb-encoding-aliases.php">mb_encoding_aliases</a> — Get aliases of a known encoding type</li><li><a href="function.mb-ereg.php">mb_ereg</a> — Regular expression match with multibyte support</li><li><a href="function.mb-ereg-match.php">mb_ereg_match</a> — Regular expression match for multibyte string</li><li><a href="function.mb-ereg-replace.php">mb_ereg_replace</a> — Replace regular expression with multibyte support</li><li><a href="function.mb-ereg-replace-callback.php">mb_ereg_replace_callback</a> — Perform a regular expression search and replace with multibyte support using a callback</li><li><a href="function.mb-ereg-search.php">mb_ereg_search</a> — Multibyte regular expression match for predefined multibyte string</li><li><a href="function.mb-ereg-search-getpos.php">mb_ereg_search_getpos</a> — Returns start point for next regular expression match</li><li><a href="function.mb-ereg-search-getregs.php">mb_ereg_search_getregs</a> — Retrieve the result from the last multibyte regular expression match</li><li><a href="function.mb-ereg-search-init.php">mb_ereg_search_init</a> — Setup string and regular expression for a multibyte regular expression match</li><li><a href="function.mb-ereg-search-pos.php">mb_ereg_search_pos</a> — Returns position and length of a matched part of the multibyte regular expression for a predefined multibyte string</li><li><a href="function.mb-ereg-search-regs.php">mb_ereg_search_regs</a> — Returns the matched part of a multibyte regular expression</li><li><a href="function.mb-ereg-search-setpos.php">mb_ereg_search_setpos</a> — Set start point of next regular expression match</li><li><a href="function.mb-eregi.php">mb_eregi</a> — Regular expression match ignoring case with multibyte support</li><li><a href="function.mb-eregi-replace.php">mb_eregi_replace</a> — Replace regular expression with multibyte support ignoring case</li><li><a href="function.mb-get-info.php">mb_get_info</a> — 获取 mbstring 的内部设置</li><li><a href="function.mb-http-input.php">mb_http_input</a> — 检测 HTTP 输入字符编码</li><li><a href="function.mb-http-output.php">mb_http_output</a> — 设置/获取 HTTP 输出字符编码</li><li><a href="function.mb-internal-encoding.php">mb_internal_encoding</a> — 设置/获取内部字符编码</li><li><a href="function.mb-language.php">mb_language</a> — 设置/获取当前的语言</li><li><a href="function.mb-lcfirst.php">mb_lcfirst</a> — Make a string's first character lowercase</li><li><a href="function.mb-list-encodings.php">mb_list_encodings</a> — 返回所有支持编码的数组</li><li><a href="function.mb-ltrim.php">mb_ltrim</a> — Strip whitespace (or other characters) from the beginning of a string</li><li><a href="function.mb-ord.php">mb_ord</a> — 获取字符的 Unicode 码位值</li><li><a href="function.mb-output-handler.php">mb_output_handler</a> — 在输出缓冲中转换字符编码的回调函数</li><li><a href="function.mb-parse-str.php">mb_parse_str</a> — 解析 GET/POST/COOKIE 数据并设置全局变量</li><li><a href="function.mb-preferred-mime-name.php">mb_preferred_mime_name</a> — 获取 MIME 字符串</li><li><a href="function.mb-regex-encoding.php">mb_regex_encoding</a> — Set/Get character encoding for multibyte regex</li><li><a href="function.mb-regex-set-options.php">mb_regex_set_options</a> — Set/Get the default options for mbregex functions</li><li><a href="function.mb-rtrim.php">mb_rtrim</a> — Strip whitespace (or other characters) from the end of a string</li><li><a href="function.mb-scrub.php">mb_scrub</a> — Replace ill-formed byte sequences with the substitute character</li><li><a href="function.mb-send-mail.php">mb_send_mail</a> — 发送编码过的邮件</li><li><a href="function.mb-split.php">mb_split</a> — 使用正则表达式分割多字节字符串</li><li><a href="function.mb-str-pad.php">mb_str_pad</a> — Pad a multibyte string to a certain length with another multibyte string</li><li><a href="function.mb-str-split.php">mb_str_split</a> — 指定多字节字符串，返回其字符数组</li><li><a href="function.mb-strcut.php">mb_strcut</a> — 获取字符的一部分</li><li><a href="function.mb-strimwidth.php">mb_strimwidth</a> — 获取按指定宽度截断的字符串</li><li><a href="function.mb-stripos.php">mb_stripos</a> — 大小写不敏感地查找字符串在另一个字符串中首次出现的位置</li><li><a href="function.mb-stristr.php">mb_stristr</a> — 大小写不敏感地查找字符串在另一个字符串里的首次出现</li><li><a href="function.mb-strlen.php">mb_strlen</a> — 获取字符串的长度</li><li><a href="function.mb-strpos.php">mb_strpos</a> — 查找字符串在另一个字符串中首次出现的位置</li><li><a href="function.mb-strrchr.php">mb_strrchr</a> — 查找指定字符在另一个字符串中最后一次的出现</li><li><a href="function.mb-strrichr.php">mb_strrichr</a> — 大小写不敏感地查找指定字符在另一个字符串中最后一次的出现</li><li><a href="function.mb-strripos.php">mb_strripos</a> — 大小写不敏感地在字符串中查找一个字符串最后出现的位置</li><li><a href="function.mb-strrpos.php">mb_strrpos</a> — 查找字符串在一个字符串中最后出现的位置</li><li><a href="function.mb-strstr.php">mb_strstr</a> — 查找字符串在另一个字符串里的首次出现</li><li><a href="function.mb-strtolower.php">mb_strtolower</a> — 使字符串小写</li><li><a href="function.mb-strtoupper.php">mb_strtoupper</a> — 使字符串大写</li><li><a href="function.mb-strwidth.php">mb_strwidth</a> — 返回字符串的宽度</li><li><a href="function.mb-substitute-character.php">mb_substitute_character</a> — 设置/获取替代字符</li><li><a href="function.mb-substr.php">mb_substr</a> — 获取部分字符串</li><li><a href="function.mb-substr-count.php">mb_substr_count</a> — 统计字符串出现的次数</li><li><a href="function.mb-trim.php">mb_trim</a> — Strip whitespace (or other characters) from the beginning and end of a string</li><li><a href="function.mb-ucfirst.php">mb_ucfirst</a> — Make a string's first character uppercase</li></ul></li></ul></div><?php manual_footer($setup); ?>