MbString类¶
属性 | 值 |
---|---|
命名空间 | fize\misc |
类名 | MbString |
方法: |
---|
方法名 | 说明 |
---|---|
checkEncoding() | 检查指定的字节流在指定的编码里是否有效 |
chr() | 获取特定字符 |
convertCase() | 对字符串进行大小写转换,转换模式由 mode 指定。 |
convertEncoding() | 转换字符的编码 |
convertKana() | 将“假名”从另一个转换为另一个(“zen-kaku”、“han-kaku”等等) |
convertVariables() | 转换一个或多个变量的字符编码 |
decodeMimeheader() | 解码 MIME 头字段中的字符串 |
decodeNumericentity() | 根据 HTML 数字字符串解码成字符 |
detectEncoding() | 检测字符的编码 |
detectOrder() | 设置/获取 字符编码的检测顺序 |
encodeMimeheader() | 为 MIME 头编码字符串 |
encodeNumericentity() | 将字符编码为HTML数字字符串引用 |
encodingAliases() | 获取已知编码类型的别名 |
eregMatch() | 正则表达式匹配多字节字符串 |
eregReplaceCallback() | 使用回调函数执行正则表达式搜索并使用多字节支持替换 |
eregReplace() | 用多字节支持替换正则表达式 |
eregSearchGetpos() | 返回下一个正则表达式匹配的起始点 |
eregSearchGetregs() | 从最后一个多字节正则表达式匹配中检索结果 |
eregSearchInit() | 为多字节正则表达式匹配设置字符串和正则表达式 |
eregSearchPos() | 返回预定义多字节正则表达式的匹配部分的位置和长度 |
eregSearchRegs() | 返回多字节正则表达式的匹配部分 |
eregSearchSetpos() | 设置下一个正则表达式匹配的起始点 |
eregSearch() | 多字节正则表达式匹配预定义的多字节字符串 |
ereg() | 正则表达式匹配多字节支持 |
eregiReplace() | 用多字节支持忽略大小写替换正则表达式 |
eregi() | 正则表达式匹配多字节支持的忽略大小写 |
getInfo() | 获取 mbstring 的内部设置 |
httpInput() | 检测 HTTP 输入字符的编码 |
httpOutput() | 设置/获取 HTTP 输出字符编码 |
internalEncoding() | 设置/获取内部字符编码 |
language() | 设置/获取当前的语言 |
listEncodings() | 返回所有支持编码的数组 |
ord() | 获取字符的代码点 |
outputHandler() | 在输出缓冲中转换字符编码的回调函数 |
parseStr() | 解析 GET/POST/COOKIE 数据并设置全局变量 |
preferredMimeName() | 获取 MIME 字符串 |
regexEncoding() | 设置/获取多字节正则表达式的字符编码 |
regexSetOptions() | 设置/获取mbregex函数的默认选项 |
scrub() | 清理格式不正确的字符 |
sendMail() | 发送编码过的邮件 |
split() | 使用正则表达式分割多字节字符串 |
strcut() | 获取字符的一部分 |
strimwidth() | 获取按指定宽度截断的字符串 |
stripos() | 大小写不敏感地查找字符串在另一个字符串中首次出现的位置 |
stristr() | 大小写不敏感地查找字符串在另一个字符串里的首次出现 |
strlen() | 获取字符串的长度 |
strpos() | 查找字符串在另一个字符串中首次出现的位置 |
strrchr() | 查找指定字符在另一个字符串中最后一次的出现 |
strrichr() | 大小写不敏感地查找指定字符在另一个字符串中最后一次的出现 |
strripos() | 大小写不敏感地在字符串中查找一个字符串最后出现的位置 |
strrpos() | 查找字符串在一个字符串中最后出现的位置 |
strstr() | 查找字符串在另一个字符串里的首次出现,并返回指定部分字符串 |
strtolower() | 使字符串小写 |
strtoupper() | 使字符串大写 |
strwidth() | 返回字符串的宽度,多字节字符通常是单字节字符的两倍宽度。 |
substituteCharacter() | 设置/获取替代字符 |
substrCount() | 统计字符串出现的次数 |
substr() | 获取部分字符串 |
方法¶
checkEncoding()¶
检查指定的字节流在指定的编码里是否有效
public static function checkEncoding (
string $var = null,
string $encoding = null
) : bool
参数: |
|
---|
该方法能有效避免所谓的"无效编码攻击(Invalid Encoding Attack)"。
参数 `$var` :
如果省略了参数 `$var` ,此函数会检查所有来自最初请求所有的输入。
chr()¶
获取特定字符
public static function chr (
int $cp,
string $encoding
) : string
参数: |
|
---|
convertCase()¶
对字符串进行大小写转换,转换模式由 mode 指定。
public static function convertCase (
string $str,
int $mode,
string $encoding = null
) : string
参数: |
|
---|
参数 `$mode` :
可以是 MB_CASE_UPPER、 MB_CASE_LOWER 和 MB_CASE_TITLE 的其中一个
参数 `$encoding` :
如果省略,则使用内部字符编码。
convertEncoding()¶
转换字符的编码
public static function convertEncoding (
string $str,
string $to_encoding,
string $from_encoding = null
) : string
参数: |
|
---|
参数 `$from_encoding` :
如果没有提供,则会使用内部(internal)编码。
convertKana()¶
将“假名”从另一个转换为另一个(“zen-kaku”、“han-kaku”等等)
public static function convertKana (
string $str,
string $option = "KV",
string $encoding = null
) : string
参数: |
|
---|
参数 `$encoding` :
如果没有提供,则会使用内部(internal)编码。
convertVariables()¶
转换一个或多个变量的字符编码
public static function convertVariables (
string $to_encoding,
string $from_encoding,
mixed &...$vars
) : string
参数: |
|
||||||||
---|---|---|---|---|---|---|---|---|---|
返回值: | 转换前的字符编码 |
该方法假设所有的参数都具有同样的编码。
参数 `$vars` :
可以接受 String、Array 和 Object 的类型。
decodeMimeheader()¶
解码 MIME 头字段中的字符串
public static function decodeMimeheader (
string $str
) : string
参数: |
|
---|
decodeNumericentity()¶
根据 HTML 数字字符串解码成字符
public static function decodeNumericentity (
string $str,
array $convmap,
string $encoding = null
) : string
参数: |
|
---|
参数 `$encoding` :
如果省略参数 `$encoding` ,则使用内部字符编码。
detectEncoding()¶
检测字符的编码
public static function detectEncoding (
string $str,
array|string $encoding_list = null,
bool $strict = false
) : string
参数: |
|
---|
编码顺序可以由数组或者逗号分隔的列表字符串指定
detectOrder()¶
设置/获取 字符编码的检测顺序
public static function detectOrder (
array|string $encoding_list = null
) : bool|array
参数: |
|
---|
设置编码检测顺序时候,成功时返回 TRUE,识别时候返回 FALSE。
在获取编码检测顺序的时候,会返回排序过的编码数组。
encodeMimeheader()¶
为 MIME 头编码字符串
public static function encodeMimeheader (
string $str,
string $charset = null,
string $transfer_encoding = "B",
string $linefeed = "
",
int $indent = 0
) : string
参数: |
|
||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
返回值: | 转换后的字符串版本以 ASCII 形式表达。 |
参数 `$transfer_encoding` :
可以是 "B"(Base64)也可以是 "Q"(Quoted-Printable)。如果未设置,将回退为 "B"。
encodeNumericentity()¶
将字符编码为HTML数字字符串引用
public static function encodeNumericentity (
string $str,
array $convmap,
string $encoding = null,
bool $is_hex = false
) : string
参数: |
|
---|
encodingAliases()¶
获取已知编码类型的别名
public static function encodingAliases (
string $encoding
) : string[]
参数: |
|
---|
eregMatch()¶
正则表达式匹配多字节字符串
public static function eregMatch (
string $pattern,
string $string,
string $option = null
) : bool
参数: |
|
---|
eregReplaceCallback()¶
使用回调函数执行正则表达式搜索并使用多字节支持替换
public static function eregReplaceCallback (
string $pattern,
callable $callback,
string $string,
string $option = "msr"
) : string
参数: |
|
---|
eregReplace()¶
用多字节支持替换正则表达式
public static function eregReplace (
string $pattern,
string $replacement,
string $string,
string $option = "msr"
) : string
参数: |
|
---|
eregSearchInit()¶
为多字节正则表达式匹配设置字符串和正则表达式
public static function eregSearchInit (
string $string,
string $pattern = null,
string $option = null
) : bool
参数: |
|
---|
eregSearchPos()¶
返回预定义多字节正则表达式的匹配部分的位置和长度
public static function eregSearchPos (
string $pattern = null,
string $option = null
) : int[]
参数: |
|
---|
eregSearchRegs()¶
返回多字节正则表达式的匹配部分
public static function eregSearchRegs (
string $pattern = null,
string $option = null
) : string[]
参数: |
|
---|
eregSearchSetpos()¶
设置下一个正则表达式匹配的起始点
public static function eregSearchSetpos (
int $position
) : bool
参数: |
|
---|
eregSearch()¶
多字节正则表达式匹配预定义的多字节字符串
public static function eregSearch (
string $pattern = null,
string $option = null
) : bool
参数: |
|
---|
ereg()¶
正则表达式匹配多字节支持
public static function ereg (
string $pattern,
string $string,
array &$regs = null
) : int
参数: |
|
---|
eregiReplace()¶
用多字节支持忽略大小写替换正则表达式
public static function eregiReplace (
string $pattern,
string $replace,
string $string,
string $option = "msr"
) : string
参数: |
|
---|
eregi()¶
正则表达式匹配多字节支持的忽略大小写
public static function eregi (
string $pattern,
string $string,
array &$regs = null
) : int
参数: |
|
---|
getInfo()¶
获取 mbstring 的内部设置
public static function getInfo (
string $type = null
) : mixed
参数: |
|
||||
---|---|---|---|---|---|
返回值: | 如果没有指定 type 将返回类型信息的数组,否则将返回指定 type 的信息。 |
httpInput()¶
检测 HTTP 输入字符的编码
public static function httpInput (
string $type = null
) : mixed
参数: |
|
||||
---|---|---|---|---|---|
返回值: | 如果没有处理过任何指定的 HTTP 输入,它将返回 FALSE。 |
参数 `$type` :
"G" 是 GET,"P" 是 POST,"C" 是 COOKIE,"S" 是 string,"L" 是 list,以及 "I" 是整个列表
httpOutput()¶
设置/获取 HTTP 输出字符编码
public static function httpOutput (
string $encoding = null
) : mixed
参数: |
|
||||
---|---|---|---|---|---|
返回值: | 如果省略了 encoding,返回当前的 HTTP 输出字符编码。否则成功时返回 TRUE, 或者在失败时返回 FALSE。 |
internalEncoding()¶
设置/获取内部字符编码
public static function internalEncoding (
string $encoding = null
) : mixed
参数: |
|
||||
---|---|---|---|---|---|
返回值: | 如果省略了 encoding,返回当前的内部字符编码。否则成功时返回 TRUE, 或者在失败时返回 FALSE。 |
language()¶
设置/获取当前的语言
public static function language (
string $language = null
) : mixed
参数: |
|
||||
---|---|---|---|---|---|
返回值: | 如果设置了 language,并且 language 是有效的,它将返回 TRUE,否则将返回 FALSE。 |
有效的语言有:"Japanese","ja","English","en" 和 "uni"(UTF-8)。
ord()¶
获取字符的代码点
public static function ord (
string $str,
string $encoding
) : int
参数: |
|
---|
outputHandler()¶
在输出缓冲中转换字符编码的回调函数
public static function outputHandler (
string $contents,
int $status
) : string
参数: |
|
---|
parseStr()¶
解析 GET/POST/COOKIE 数据并设置全局变量
public static function parseStr (
string $encoded_string,
array &$result = null
) : bool
参数: |
|
---|
preferredMimeName()¶
获取 MIME 字符串
public static function preferredMimeName (
string $encoding
) : string
参数: |
|
---|
regexEncoding()¶
设置/获取多字节正则表达式的字符编码
public static function regexEncoding (
string $encoding = null
) : bool|string
参数: |
|
||||
---|---|---|---|---|---|
返回值: | 设置时返回true或false,获取时返回string |
regexSetOptions()¶
设置/获取mbregex函数的默认选项
public static function regexSetOptions (
string $options = null
) : string
参数: |
|
---|
scrub()¶
清理格式不正确的字符
public static function scrub (
string $str,
string $encoding
) : string
参数: |
|
---|
sendMail()¶
发送编码过的邮件
public static function sendMail (
string $to,
string $subject,
string $message,
string $additional_headers = null,
string $additional_parameter = null
) : bool
参数: |
|
---|
可通过逗号分隔地址的 `$to` 来指定多个收件人。该参数不会被自动编码
参数 `$additional_parameter` :
在使用 sendmail 时对设置正确的返回路径头很有帮助
split()¶
使用正则表达式分割多字节字符串
public static function split (
string $pattern,
string $string,
int $limit = null
) : array
参数: |
|
---|
strcut()¶
获取字符的一部分
public static function strcut (
string $str,
int $start,
int $length = null,
string $encoding = null
) : string
参数: |
|
---|
参数 `$start` :
负表示返回的字符串是从 str 末尾处第 start 个字节开始的
strimwidth()¶
获取按指定宽度截断的字符串
public static function strimwidth (
string $str,
int $start,
int $width,
string $trimmarker = null,
string $encoding = null
) : string
参数: |
|
---|
参数 `$start` :
从这些字符数开始的截取字符串。(默认是 0 个字符)。
如果 start 是负数,就是字符串结尾处的字符数。
stripos()¶
大小写不敏感地查找字符串在另一个字符串中首次出现的位置
public static function stripos (
string $haystack,
string $needle,
int $offset = 0,
string $encoding = null
) : int|bool
参数: |
|
||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
返回值: | 没找到返回false |
参数 `$offset` :
如果是负数,就从字符串的尾部开始统计。
参数 `$encoding` :
如果省略了它,将使用内部字符编码。
stristr()¶
大小写不敏感地查找字符串在另一个字符串里的首次出现
public static function stristr (
string $haystack,
string $needle,
bool $before_needle = false,
string $encoding = null
) : string|bool
参数: |
|
||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
返回值: | 返回指定部分字符串,没找到时返回false |
参数 `$encoding` :
如果省略了它,将使用内部字符编码。
strlen()¶
获取字符串的长度
public static function strlen (
string $str,
string $encoding = null
) : int|bool
参数: |
|
||||||
---|---|---|---|---|---|---|---|
返回值: | 如果给定的 encoding 无效则返回 FALSE |
strpos()¶
查找字符串在另一个字符串中首次出现的位置
public static function strpos (
string $haystack,
string $needle,
int $offset = 0,
string $encoding = null
) : int|bool
参数: |
|
||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
返回值: | 没找到时返回false |
参数 `$offset` :
如果没有提供该参数,将会使用 0。负数的 offset 会从字符串尾部开始统计。
参数 `$encoding` :
如果省略,则使用内部字符编码。
strrchr()¶
查找指定字符在另一个字符串中最后一次的出现
public static function strrchr (
string $haystack,
string $needle,
bool $before_needle = false,
string $encoding = null
) : string|bool
参数: |
|
||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
返回值: | 返回指定部分字符串,没找到时返回false |
参数 `$encoding` :
如果省略,则使用内部字符编码。
strrichr()¶
大小写不敏感地查找指定字符在另一个字符串中最后一次的出现
public static function strrichr (
string $haystack,
string $needle,
bool $before_needle = false,
string $encoding = null
) : string|bool
参数: |
|
||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
返回值: | 返回指定部分字符串,没找到时返回false |
参数 `$encoding` :
如果省略,则使用内部字符编码。
strripos()¶
大小写不敏感地在字符串中查找一个字符串最后出现的位置
public static function strripos (
string $haystack,
string $needle,
int $offset = 0,
string $encoding = null
) : int|bool
参数: |
|
||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
返回值: | 没找到时返回false |
参数 `$encoding` :
如果省略,则使用内部字符编码。
strrpos()¶
查找字符串在一个字符串中最后出现的位置
public static function strrpos (
string $haystack,
string $needle,
int $offset = 0,
string $encoding = null
) : int|bool
参数: |
|
||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
返回值: | 没找到时返回false |
参数 `$encoding` :
如果省略,则使用内部字符编码。
strstr()¶
查找字符串在另一个字符串里的首次出现,并返回指定部分字符串
public static function strstr (
string $haystack,
string $needle,
bool $before_needle = false,
string $encoding = null
) : string|bool
参数: |
|
||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
返回值: | 没找到时返回false |
参数 `$encoding` :
如果省略,则使用内部字符编码。
strtolower()¶
使字符串小写
public static function strtolower (
string $str,
string $encoding = null
) : string
参数: |
|
---|
参数 `$encoding` :
如果省略,则使用内部字符编码。
strtoupper()¶
使字符串大写
public static function strtoupper (
string $str,
string $encoding = null
) : string
参数: |
|
---|
参数 `$encoding` :
如果省略,则使用内部字符编码。
strwidth()¶
返回字符串的宽度,多字节字符通常是单字节字符的两倍宽度。
public static function strwidth (
string $str,
string $encoding = null
) : int
参数: |
|
---|
参数 `$encoding` :
如果省略,则使用内部字符编码。
substituteCharacter()¶
设置/获取替代字符
public static function substituteCharacter (
mixed $substrchar = null
) : mixed
参数: |
|
||||
---|---|---|---|---|---|
返回值: | 设置时,在成功时返回 TRUE,失败时返回 FALSE。否则返回当前设置。 |
substrCount()¶
统计字符串出现的次数
public static function substrCount (
string $haystack,
string $needle,
string $encoding = null
) : int
参数: |
|
---|
参数 `$encoding` :
如果省略,则使用内部字符编码。
substr()¶
获取部分字符串
public static function substr (
string $str,
int $start,
int $length = null,
string $encoding = null
) : string
参数: |
|
---|
参数 `$encoding` :
如果省略,则使用内部字符编码。