多字节字符串 函数 业 ,精于勤 荒于嬉.
- 多字节字符串 函数 mb_check_encoding 检查字符串在指定的编码里是否有效
-
发表日期:2021-07-01 08:55:50 | 来源: | 分类:多字节字符串 函数
-
mb_check_encoding
(PHP 4 >= 4.4.3, PHP 5 >= 5.1.3, PHP 7, PHP 8)
mb_check_encoding — 检查字符串在指定的编码里是否有效
说明
mb_check_encoding(string$var
=null
, string$encoding
= mb_internal_encoding()): bool检查指定的字节流在指定的编码里是否有效。它能有效避免所谓的“无效编码攻击(Invalid Encoding Attack)”。
参数
-
var
-
要检查的字节流。如果省略了这个参数,此函数会检查所有来自最初请求所有的输入。
-
encoding
-
期望的编码。
返回值
成功时返回
true
, 或者在失败时返回false
。 -
- 多字节字符串 函数 mb_convert_case 对字符串进行大小写转换
-
发表日期:2021-07-01 08:55:50 | 来源: | 分类:多字节字符串 函数
-
示例1
<?php $str = "mary had a Little lamb and she loved it so"; $str = mb_convert_case($str, MB_CASE_UPPER, "UTF-8"); echo $str; // 输出 MARY HAD A LITTLE LAMB AND SHE LOVED IT SO $str = mb_convert_case($str, MB_CASE_TITLE, "UTF-8"); echo $str; // 输出 Mary Had A Little Lamb And She Loved It So ?>
示例2
<?php $str = "Τάχιστη αλώπηξ βαφής ψημένη γη, δρασκελίζει υπέρ νωθρού κυνός"; $str = mb_convert_case($str, MB_CASE_UPPER, "UTF-8"); echo $str; // 输出 ΤΆΧΙΣΤΗ ΑΛΏΠΗΞ ΒΑΦΉΣ ΨΗΜΈΝΗ ΓΗ, ΔΡΑΣΚΕΛΊΖΕΙ ΥΠΈΡ ΝΩΘΡΟΎ ΚΥΝΌΣ $str = mb_convert_case($str, MB_CASE_TITLE, "UTF-8"); echo $str; // 输出 Τάχιστη Αλώπηξ Βαφήσ Ψημένη Γη, Δρασκελίζει Υπέρ Νωθρού Κυνόσ ?>
- 多字节字符串 函数 mb_convert_encoding 转换字符的编码
-
发表日期:2021-07-01 08:55:51 | 来源: | 分类:多字节字符串 函数
-
示例1
<?php /* 转换内部编码为 SJIS */ $str = mb_convert_encoding($str, "SJIS"); /* 将 EUC-JP 转换成 UTF-7 */ $str = mb_convert_encoding($str, "UTF-7", "EUC-JP"); /* 从 JIS, eucjp-win, sjis-win 中自动检测编码,并转换 str 到 UCS-2LE */ $str = mb_convert_encoding($str, "UCS-2LE", "JIS, eucjp-win, sjis-win"); /* "auto" 扩展成 "ASCII,JIS,UTF-8,EUC-JP,SJIS" */ $str = mb_convert_encoding($str, "EUC-JP", "auto"); ?>
- 多字节字符串 函数 mb_convert_kana Convert "kana" one from another ("zen-kaku", "han-kaku" and more)
-
发表日期:2021-07-01 08:55:50 | 来源: | 分类:多字节字符串 函数
-
示例1
<?php /* Convert all "kana" to "zen-kaku" "kata-kana" */ $str = mb_convert_kana($str, "KVC"); /* Convert "han-kaku" "kata-kana" to "zen-kaku" "kata-kana" and "zen-kaku" alphanumeric to "han-kaku" */ $str = mb_convert_kana($str, "KVa"); ?>
- 多字节字符串 函数 mb_convert_variables 转换一个或多个变量的字符编码
-
发表日期:2021-07-01 08:55:51 | 来源: | 分类:多字节字符串 函数
-
示例1
<?php /* 转换变量 $post1、$post2 编码为内部(internal)编码 */ $interenc = mb_internal_encoding(); $inputenc = mb_convert_variables($interenc, "ASCII,UTF-8,SJIS-win", $post1, $post2); ?>
- 多字节字符串 函数 mb_decode_mimeheader 解码 MIME 头字段中的字符串
-
发表日期:2021-07-01 08:55:51 | 来源: | 分类:多字节字符串 函数
-
mb_decode_mimeheader
(PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8)
mb_decode_mimeheader — 解码 MIME 头字段中的字符串
说明
mb_decode_mimeheader(string$str
): string解码 MIME 头中编码过的字符串
str
。参数
-
str
-
要解码的 string。
返回值
以内部(internal)字符编码解码的 string。
-
- 多字节字符串 函数 mb_decode_numericentity 根据 HTML 数字字符串解码成字符
-
发表日期:2021-07-01 08:55:51 | 来源: | 分类:多字节字符串 函数
-
示例1
<?php $convmap = array (int start_code1, int end_code1, int offset1, int mask1,int start_code2, int end_code2, int offset2, int mask2, ........ int start_codeN, int end_codeN, int offsetN, int maskN ); // Specify Unicode value for start_codeN and end_codeN // Add offsetN to value and take bit-wise 'AND' with maskN, // then convert value to numeric string reference. ?>
示例2
<?php function escape_javascript_string($str) { $map = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0, 490,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0, 990,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1491,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1991,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 2491,1,1,1,1,1,1, 255]; // Char encoding is UTF-8 $mblen = mb_strlen($str, 'UTF-8'); $utf32 = bin2hex(mb_convert_encoding($str, 'UTF-32', 'UTF-8')); for ($i=0, $encoded='';$i < $mblen;$i++) { $u = substr($utf32, $i*8, 8); $v = base_convert($u, 16, 10); if ($v < 256 && $map[$v]) { $encoded .= '\\x'.substr($u, 6,2); } else if ($v == 2028) { $encoded .= '\\u2028'; } else if ($v == 2029) { $encoded .= '\\u2029'; } else { $encoded .= mb_convert_encoding(hex2bin($u), 'UTF-8', 'UTF-32'); } } return $encoded; } // Test data$convmap = [ 0x0, 0xffff, 0, 0xffff ]; $msg = ''; for ($i=0;$i < 1000;$i++) { // chr() cannot generate correct UTF-8 data larger value than 128, use mb_decode_numericentity(). $msg .= mb_decode_numericentity('&#'.$i.';', $convmap, 'UTF-8'); } // var_dump($msg); var_dump(escape_javascript_string($msg));
- 多字节字符串 函数 mb_detect_encoding 检测字符的编码
-
发表日期:2021-07-01 08:55:51 | 来源: | 分类:多字节字符串 函数
-
示例1
<?php /* 使用当前的 detect_order 来检测字符编码 */ echo mb_detect_encoding($str); /* "auto" 将根据 mbstring.language 来扩展 */ echo mb_detect_encoding($str, "auto"); /* 通过逗号分隔的列表来指定编码列表 encoding_list */ echo mb_detect_encoding($str, "JIS, eucjp-win, sjis-win"); /* 使用数组来指定编码列表 encoding_list */ $ary[] = "ASCII"; $ary[] = "JIS"; $ary[] = "EUC-JP"; echo mb_detect_encoding($str, $ary); ?>
- 多字节字符串 函数 mb_detect_order 设置/获取 字符编码的检测顺序
-
发表日期:2021-07-01 08:55:51 | 来源: | 分类:多字节字符串 函数
-
示例1
<?php /* 为检测顺序设置枚举列表 */ mb_detect_order("eucjp-win,sjis-win,UTF-8"); /* 通过数组设置检测顺序 */ $ary[] = "ASCII"; $ary[] = "JIS"; $ary[] = "EUC-JP"; mb_detect_order($ary); /* 显示当前的检测顺序 */ echo implode(", ", mb_detect_order()); ?>
- 多字节字符串 函数 mb_encode_mimeheader 为 MIME 头编码字符串
-
发表日期:2021-07-01 08:55:51 | 来源: | 分类:多字节字符串 函数
-
示例1
<?php $name = ""; // kanji$mbox = "kru"; $doma = "gtinn.mon"; $addr = mb_encode_mimeheader($name, "UTF-7", "Q") . " <" . $mbox . "@" . $doma . ">"; echo $addr; ?>
- 多字节字符串 函数 mb_encode_numericentity Encode character to HTML numeric string reference
-
发表日期:2021-07-01 08:55:51 | 来源: | 分类:多字节字符串 函数
-
示例1
<?php $convmap = array ( int start_code1, int end_code1, int offset1, int mask1, int start_code2, int end_code2, int offset2, int mask2, ........ int start_codeN, int end_codeN, int offsetN, int maskN ); // Specify Unicode value for start_codeN and end_codeN// Add offsetN to value and take bit-wise 'AND' with maskN, then// it converts value to numeric string reference.?>
示例2
<?php /* Convert Left side of ISO-8859-1 to HTML numeric character reference */ $convmap = array(0x80, 0xff, 0, 0xff); $str = mb_encode_numericentity($str, $convmap, "ISO-8859-1"); /* Convert user defined SJIS-win code in block 95-104 to numeric string reference */ $convmap = array( 0xe000, 0xe03e, 0x1040, 0xffff, 0xe03f, 0xe0bb, 0x1041, 0xffff, 0xe0bc, 0xe0fa, 0x1084, 0xffff, 0xe0fb, 0xe177, 0x1085, 0xffff, 0xe178, 0xe1b6, 0x10c8, 0xffff, 0xe1b7, 0xe233, 0x10c9, 0xffff, 0xe234, 0xe272, 0x110c, 0xffff, 0xe273, 0xe2ef, 0x110d, 0xffff, 0xe2f0, 0xe32e, 0x1150, 0xffff, 0xe32f, 0xe3ab, 0x1151, 0xffff ); $str = mb_encode_numericentity($str, $convmap, "sjis-win"); ?>
- 多字节字符串 函数 mb_encoding_aliases Get aliases of a known encoding type
-
发表日期:2021-07-01 08:55:51 | 来源: | 分类:多字节字符串 函数
-
示例1
<?php $encoding = 'ASCII'; $known_encodings = mb_list_encodings(); if (in_array($encoding, $known_encodings)) { $aliases = mb_encoding_aliases($encoding); print_r($aliases); } else { echo "Unknown ($encoding) encoding.\n"; } ?>
- 多字节字符串 函数 mb_ereg_match Regular expression match for multibyte string
-
发表日期:2021-07-01 08:55:51 | 来源: | 分类:多字节字符串 函数
-
mb_ereg_match
(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)
mb_ereg_match — Regular expression match for multibyte string
说明
mb_ereg_match(string$pattern
, string$string
, string|null$options
=null
): boolA regular expression match for a multibyte string
参数
-
pattern
-
The regular expression pattern.
-
string
-
The string being evaluated.
-
options
-
The search option. See mb_regex_set_options() for explanation.
返回值
Returns
true
ifstring
matches the regular expressionpattern
,false
if not.更新日志
版本 说明 8.0.0 options
is nullable now.注释
注意:
mb_regex_encoding() 指定的内部编码或字符编码将会当作此函数用的字符编码。
参见
- mb_regex_encoding() - Set/Get character encoding for multibyte regex
- mb_ereg() - Regular expression match with multibyte support
-
- 多字节字符串 函数 mb_ereg_replace_callback Perform a regular expression search and replace with multibyte support using a callback
-
发表日期:2021-07-01 08:55:51 | 来源: | 分类:多字节字符串 函数
-
示例1
<?php // this text was used in 2002// we want to get this up to date for 2003$text = "April fools day is 04/01/2002\n"; $text.= "Last christmas was 12/24/2001\n"; // the callback functionfunction next_year($matches){ // as usual: $matches[0] is the complete match // $matches[1] the match for the first subpattern // enclosed in '(...)' and so on return $matches[1].($matches[2]+1); } echo mb_ereg_replace_callback( "(\d{ 2} /\d{ 2} /)(\d{ 4} )", "next_year", $text); ?>
示例2
<?php // this text was used in 2002// we want to get this up to date for 2003$text = "April fools day is 04/01/2002\n"; $text.= "Last christmas was 12/24/2001\n"; echo mb_ereg_replace_callback( "(\d{ 2} /\d{ 2} /)(\d{ 4} )", function ($matches) { return $matches[1].($matches[2]+1); } , $text); ?>
- 多字节字符串 函数 mb_ereg_replace Replace regular expression with multibyte support
-
发表日期:2021-07-01 08:55:51 | 来源: | 分类:多字节字符串 函数
-
mb_ereg_replace
(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)
mb_ereg_replace — Replace regular expression with multibyte support
说明
mb_ereg_replace(
string$pattern
,
string$replacement
,
string$string
,
string|null$options
=null
): string|false|nullScans
string
for matches topattern
, then replaces the matched text withreplacement
参数
-
pattern
-
The regular expression pattern.
Multibyte characters may be used in
pattern
. -
replacement
-
The replacement text.
-
string
-
The string being checked.
-
options
- The search option. See mb_regex_set_options() for explanation.
返回值
The resultant string on success, or
false
on error. Ifstring
is not valid for the current encoding,null
is returned.更新日志
版本 说明 8.0.0 options
is nullable now.7.1.0 The function checks whether string
is valid for the current encoding.7.1.0 The e
modifier has been deprecated.注释
注意:
mb_regex_encoding() 指定的内部编码或字符编码将会当作此函数用的字符编码。
警告处理非信任的输入时从不使用
e
修饰符,就不会转码(即调用 preg_replace())。不注意这些会很可能会导致应用程序引发远程代码执行的漏洞。参见
- mb_regex_encoding() - Set/Get character encoding for multibyte regex
- mb_eregi_replace() - Replace regular expression with multibyte support ignoring case
-
- 多字节字符串 函数 mb_ereg_search_getpos Returns start point for next regular expression match
-
发表日期:2021-07-01 08:55:51 | 来源: | 分类:多字节字符串 函数
-
mb_ereg_search_getpos
(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)
mb_ereg_search_getpos — Returns start point for next regular expression match
说明
mb_ereg_search_getpos(): intReturns the start point for the next regular expression match.
参数
此函数没有参数。
返回值
mb_ereg_search_getpos() returns the point to start regular expression match for mb_ereg_search(), mb_ereg_search_pos(), mb_ereg_search_regs(). The position is represented by bytes from the head of string.
注释
注意:
mb_regex_encoding() 指定的内部编码或字符编码将会当作此函数用的字符编码。
参见
- mb_regex_encoding() - Set/Get character encoding for multibyte regex
- mb_ereg_search_setpos() - Set start point of next regular expression match
- 多字节字符串 函数 mb_ereg_search_getregs Retrieve the result from the last multibyte regular expression match
-
发表日期:2021-07-01 08:55:52 | 来源: | 分类:多字节字符串 函数
-
mb_ereg_search_getregs
(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)
mb_ereg_search_getregs — Retrieve the result from the last multibyte regular expression match
说明
mb_ereg_search_getregs(): array|falseRetrieve the result from the last multibyte regular expression match
参数
此函数没有参数。
返回值
An array including the sub-string of matched part by last mb_ereg_search(), mb_ereg_search_pos(), mb_ereg_search_regs(). If there are some matches, the first element will have the matched sub-string, the second element will have the first part grouped with brackets, the third element will have the second part grouped with brackets, and so on. It returns
false
on error.注释
注意:
mb_regex_encoding() 指定的内部编码或字符编码将会当作此函数用的字符编码。
参见
- mb_regex_encoding() - Set/Get character encoding for multibyte regex
- mb_ereg_search_init() - Setup string and regular expression for a multibyte regular expression match
- 多字节字符串 函数 mb_ereg_search_init Setup string and regular expression for a multibyte regular expression match
-
发表日期:2021-07-01 08:55:51 | 来源: | 分类:多字节字符串 函数
-
mb_ereg_search_init
(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)
mb_ereg_search_init — Setup string and regular expression for a multibyte regular expression match
说明
mb_ereg_search_init(string$string
, string|null$pattern
=null
, string|null$options
=null
): boolmb_ereg_search_init() sets
string
andpattern
for a multibyte regular expression. These values are used for mb_ereg_search(), mb_ereg_search_pos(), and mb_ereg_search_regs().参数
-
string
-
The search string.
-
pattern
-
The search pattern.
-
options
-
The search option. See mb_regex_set_options() for explanation.
返回值
成功时返回
true
, 或者在失败时返回false
。更新日志
版本 说明 8.0.0 pattern
andoptions
are nullable now.注释
注意:
mb_regex_encoding() 指定的内部编码或字符编码将会当作此函数用的字符编码。
参见
- mb_regex_encoding() - Set/Get character encoding for multibyte regex
- mb_ereg_search_regs() - Returns the matched part of a multibyte regular expression
-
- 多字节字符串 函数 mb_ereg_search_pos Returns position and length of a matched part of the multibyte regular expression for a predefined multibyte string
-
发表日期:2021-07-01 08:55:51 | 来源: | 分类:多字节字符串 函数
-
mb_ereg_search_pos
(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)
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_pos(string|null$pattern
=null
, string|null$options
=null
): array|falseReturns position and length of a matched part of the multibyte regular expression for a predefined multibyte string
The string for match is specified by mb_ereg_search_init(). If it is not specified, the previous one will be used.
参数
-
pattern
-
The search pattern.
-
options
-
The search option. See mb_regex_set_options() for explanation.
返回值
An array containing two elements. The first element is the offset, in bytes, where the match begins relative to the start of the search string, and the second element is the length in bytes of the match.
If an error occurs,
false
is returned.更新日志
版本 说明 8.0.0 pattern
andoptions
are nullable now.注释
注意:
mb_regex_encoding() 指定的内部编码或字符编码将会当作此函数用的字符编码。
参见
- mb_regex_encoding() - Set/Get character encoding for multibyte regex
- mb_ereg_search_init() - Setup string and regular expression for a multibyte regular expression match
-
- 多字节字符串 函数 mb_ereg_search_regs Returns the matched part of a multibyte regular expression
-
发表日期:2021-07-01 08:55:52 | 来源: | 分类:多字节字符串 函数
-
mb_ereg_search_regs
(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)
mb_ereg_search_regs — Returns the matched part of a multibyte regular expression
说明
mb_ereg_search_regs(string|null$pattern
=null
, string|null$options
=null
): array|falseReturns the matched part of a multibyte regular expression.
参数
-
pattern
-
The search pattern.
-
options
-
The search option. See mb_regex_set_options() for explanation.
返回值
mb_ereg_search_regs() executes the multibyte regular expression match, and if there are some matched part, it returns an array including substring of matched part as first element, the first grouped part with brackets as second element, the second grouped part as third element, and so on. It returns
false
on error.更新日志
版本 说明 8.0.0 pattern
andoptions
are nullable now.注释
注意:
mb_regex_encoding() 指定的内部编码或字符编码将会当作此函数用的字符编码。
参见
- mb_regex_encoding() - Set/Get character encoding for multibyte regex
- mb_ereg_search_init() - Setup string and regular expression for a multibyte regular expression match
-
- PHP杂项(34)
- PHP基础-李炎恢系列课程(20)
- 中文函数手册(0)
- 错误处理 函数(13)
- OPcache 函数(6)
- PHP 选项/信息 函数(54)
- Zip 函数(10)
- Hash 函数(15)
- OpenSSL 函数(63)
- Date/Time 函数(51)
- 目录函数(9)
- Fileinfo 函数(6)
- iconv 函数(11)
- 文件系统函数(81)
- 多字节字符串 函数(57)
- GD 和图像处理 函数(114)
- 可交换图像信息(5)
- Math 函数(50)
- 程序执行函数(11)
- PCNTL 函数(23)
- JSON 函数(4)
- SPL 函数(15)
- URL 函数(10)
- cURL 函数(32)
- 网络 函数(33)
- FTP 函数(36)
- Session 函数(23)
- PCRE 函数(11)
- PCRE 正则语法(19)
- 数组 函数(81)
- 类/对象 函数(18)
- 函数处理 函数(13)
- 变量处理 函数(37)
- SimpleXML 函数(3)
- 杂项 函数(31)
- 字符串 函数(101)