CakeFest 2024: The Official CakePHP Conference

mb_ereg_search_pos

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

mb_ereg_search_pos指定したマルチバイト文字列が正規表現に一致する部分の位置と長さを返す

説明

mb_ereg_search_pos(?string $pattern = null, ?string $options = null): array|false

マルチバイト文字列の中で正規表現に一致した部分の位置と長さを配列で返します。

検索対象の文字列は、mb_ereg_search_init() により設定します。省略した場合は、前回のものが利用されます。

パラメータ

pattern

検索パターン。

options

検索オプション。説明は、mb_regex_set_options() を参照ください。

戻り値

ふたつの要素からなる配列を返します。最初の要素はオフセットをバイト単位で表したもので、 マッチしたのが検索文字列の先頭から何バイト目かを示します。 二番目の要素はマッチした部分の長さをバイト単位で表したものです。

エラーが発生した場合は false を返します。

変更履歴

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

注意

注意:

内部エンコーディングあるいは mb_regex_encoding() で指定した文字エンコーディングを、 この関数の文字エンコーディングとして使用します。

参考

  • mb_regex_encoding() - 現在のマルチバイト正規表現用のエンコーディングを取得または設定する
  • mb_ereg_search_init() - マルチバイト正規表現検索用の文字列と正規表現を設定する

add a note

User Contributed Notes 1 note

up
1
v dot picture at free dot fr
2 years ago
This function is absolutely not multibyte-safe, it actually returns the position of the match as if the string was not multibyte.

The results of this function are exactly the same as if you were using preg_match_all with PREG_OFFSET_CAPTURE, even with the "unicode" flag it's simply NOT working

(Bug report filed)
To Top