mb_regex_encoding

(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)

mb_regex_encoding現在のマルチバイト正規表現用のエンコーディングを取得または設定する

説明

mb_regex_encoding(?string $encoding = null): string|bool

現在のマルチバイト正規表現用のエンコーディングを取得または設定する

パラメータ

encoding

encoding パラメータには文字エンコーディングを指定します。省略した場合、もしくは null の場合は、 内部文字エンコーディングを使用します。

戻り値

encoding が設定された場合、 成功した場合に true を、失敗した場合に false を返します。 このとき、内部文字エンコーディングは変更されません。 encoding が省略された場合、 現在のマルチバイト正規表現用のエンコーディング名を返します。

変更履歴

バージョン 説明
8.0.0 encoding は、nullable になりました。

参考

  • mb_internal_encoding() - 内部文字エンコーディングを設定あるいは取得する
  • mb_ereg() - マルチバイト対応の正規表現マッチ

add a note

User Contributed Notes 4 notes

up
3
GerryH
7 years ago
mb_ereg functionality is provided via Oniguruma RegEx library and not via PCRE. mb_regex_encoding() does only support a subset of encoding names, compared to mb_list_encodings() and mb_encoding_aliases().Currently the following names are supported (case-insensitive):UCS-4UCS-4LEUTF-32UTF-32BEUTF-32LEUTF-16UTF-16BEUTF-16LEUTF-8utf8ASCIIUS-ASCIIEUC-JPeucJPx-euc-jpSJISeucJP-winSJIS-winCP932MS932Windows-31JISO-8859-1ISO-8859-2ISO-8859-3ISO-8859-4ISO-8859-5ISO-8859-6ISO-8859-7ISO-8859-8ISO-8859-9ISO-8859-10ISO-8859-13ISO-8859-14ISO-8859-15ISO-8859-16EUC-CNEUC_CNeucCNgb2312EUC-TWEUC_TWeucTWBIG-5CN-BIG5BIG-FIVEBIGFIVEEUC-KREUC_KReucKRKOI8-RKOI8RThe list is a mixture of base names and aliases and applies to PHP 5.4.45 (Oniguruma lib v4.7.1), PHP 5.6.31 (v5.9.5), PHP 7.0.22 (v5.9.6) and PHP 7.1.8 (v5.9.6). Be aware of the inconsistency: mb_regex_encoding() accepts for example the base name 'UTF-8' and its only alias 'utf8', but it does not accept aliases 'utf16', 'utf32' or 'latin1'.Additionally note, that the informal name/alias 'latin9' for ISO/IEC 8859-15:1999 (including the Euro sign on 0xA4) is also not known by mb_list_encodings(). It can only be adressed as 'ISO-8859-15' or 'ISO_8859-15' and for mb_regex_encoding() solely as 'ISO-8859-15'.
up
4
php dot net at phor dot net
14 years ago
Beware, mb_regex_encoding does not support the same set of encodings as listed in mb_list_encodings.phpExample:<?phpmb_internal_encoding('CP936');mb_regex_encoding('CP936'); # this line produces an error ?>
up
0
code at roberthairgrove dot com
8 years ago
mb_regex_encoding does not recognize CP1252 or Windows-1252 as valid encodings, although they are in the list generated by mb_list_encodings.ISO-8859-1 (AKA "Latin-1") is supported, but it's not the same as the Windows variety of Latin-1.
up
-4
Anonymous
16 years ago
To change algo the regex_encodign<?phpecho "current mb_internal_encoding: ".mb_internal_encoding()."<br />";echo "changing mb_internal_encoding to UTF-8<br />";mb_internal_encoding("UTF-8"); echo "new mb_internal_encoding: ".mb_internal_encoding()."<br />";echo "current mb_regex_encoding: ".mb_regex_encoding()."<br />";echo "changing mb_regex_encoding to UTF-8<br />";mb_regex_encoding('UTF-8');echo "new mb_regex_encoding: ".mb_regex_encoding()."<br />";?>
To Top