downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

> <リソース型
Last updated: Fri, 13 Nov 2009

view this page in

定義済み定数

以下の定数が定義されています。 この関数の拡張モジュールが PHP 組み込みでコンパイルされているか、 実行時に動的にロードされている場合のみ使用可能です。

PREG 定数
定数 説明
PREG_PATTERN_ORDER $matches[0] はパターン全体にマッチした文字列の配列、 $matches[1] は第 1 のキャプチャ用サブパターンにマッチした文字列の配列、 といったように結果の順序を指定します。 このフラグは、preg_match_all() でのみ使用されます。
PREG_SET_ORDER $matches[0] は 1 回目のマッチングでキャプチャした値の配列、 $matches[1] は 2 回目のマッチングでキャプチャした値の配列、 といったように結果の順序を指定します。 このフラグは、preg_match_all() でのみ使用されます。
PREG_OFFSET_CAPTURE PREG_SPLIT_OFFSET_CAPTURE の説明を参照してください。 このフラグは、PHP 4.3.0 以降で利用可能です。
PREG_SPLIT_NO_EMPTY このフラグは、preg_split() が、空文字列でないものだけ を返すようにします。
PREG_SPLIT_DELIM_CAPTURE このフラグは、preg_split() が 文字列分割用のパターン中のカッコによるサブパターンでキャプチャされた値も 同時に返すようにします。 このフラグは、PHP 4.0.5 以降で利用可能です。
PREG_SPLIT_OFFSET_CAPTURE このフラグを設定した場合、各マッチに対応する文字列のオフセットも返されます。 これにより、返り値は配列となり、配列の要素 0 はマッチした文字列、 要素 1 は対象文字列中におけるマッチした文字列のオフセット値となることに注意してください。 このフラグは、PHP 4.3.0 以降で利用可能で、 preg_split() のみで使用されます。
PREG_NO_ERROR エラーが存在しなかった場合に preg_last_error() から返されます。 PHP 5.2.0 以降で使用可能です。
PREG_INTERNAL_ERROR PCRE 内部エラーが発生した場合に preg_last_error() から返されます。 PHP 5.2.0 以降で使用可能です。
PREG_BACKTRACK_LIMIT_ERROR backtrack limit に達した場合に preg_last_error() から返されます。 PHP 5.2.0 以降で使用可能です。
PREG_RECURSION_LIMIT_ERROR recursion limit に達した場合に preg_last_error() から返されます。 PHP 5.2.0 以降で使用可能です。
PREG_BAD_UTF8_ERROR 壊れている UTF8 データによって直近のエラーが発生した場合に preg_last_error() から返されます (UTF-8 モード で正規表現を実行した場合のみ)。 PHP 5.2.0 以降で使用可能です。
PREG_BAD_UTF8_OFFSET_ERROR オフセットが妥当な UTF-8 コードポイントの開始位置に対応しない場合に preg_last_error() から返されます (UTF-8 モード で正規表現を実行した場合のみ)。 PHP 5.3.0 以降で使用可能です。
PCRE_VERSION PCRE のバージョンおよびリリース日 (例: "7.0 18-Dec-2006")。 PHP 5.2.4 以降で使用可能です。


add a note add a note User Contributed Notes
定義済み定数
Bastiaan
23-Jan-2009 01:22
[editor note] This example script is misleading. preg_last_error() only returns PREG_*_ERROR constants.

This function might come in handy to debug regular expressions in preg_.. calls

<?php
function pcre_error_deocde() {
    switch (
preg_last_error()) {
          case
PREG_PATTERN_ORDER:
          print
"Orders results so that $matches[0] is an array of full pattern matches, $matches[1] is an array of strings matched by the first parenthesized subpattern, and so on. This flag is only used with preg_match_all().\n";
          break;
          case
PREG_SET_ORDER:
          print
"Orders results so that $matches[0] is an array of first set of matches, $matches[1] is an array of second set of matches, and so on. This flag is only used with preg_match_all().\n";
          break;
          case
PREG_OFFSET_CAPTURE:
          print
"See the description of PREG_SPLIT_OFFSET_CAPTURE. This flag is available since PHP 4.3.0.\n";
          break;
          case
PREG_SPLIT_NO_EMPTY:
          print
"This flag tells preg_split() to return only non-empty pieces.\n";
          break;
          case
PREG_SPLIT_DELIM_CAPTURE:
          print
"This flag tells preg_split() to capture parenthesized expression in the delimiter pattern as well. This flag is available since PHP 4.0.5.\n";
          break;
          case
PREG_SPLIT_OFFSET_CAPTURE:
          print
"If this flag is set, for every occurring match the appendant string offset will also be returned. Note that this changes the return values in an array where every element is an array consisting of the matched string at offset 0 and its string offset within subject at offset 1. This flag is available since PHP 4.3.0 and is only used for preg_split().\n";
          break;
          case
PREG_NO_ERROR:
         
// do not print in this case
          //print "Returned by preg_last_error() if there were no errors. Available since PHP 5.2.0.\n";
         
break;
          case
PREG_INTERNAL_ERROR:
          print
"Returned by preg_last_error() if there was an internal PCRE error. Available since PHP 5.2.0.\n";
          break;
          case
PREG_BACKTRACK_LIMIT_ERROR:
          print
"Returned by preg_last_error() if backtrack limit was exhausted. Available since PHP 5.2.0.\n";
          break;
          case
PREG_RECURSION_LIMIT_ERROR:
          print
"Returned by preg_last_error() if recursion limit was exhausted. Available since PHP 5.2.0.\n";
          break;
          case
PREG_BAD_UTF8_ERROR:
          print
"Returned by preg_last_error() if the last error was caused by malformed UTF-8 data (only when running a regex in UTF-8 mode). Available since PHP 5.2.0.\n";
          break;
          case
PREG_BAD_UTF8_OFFSET_ERROR:
          print
"Returned by preg_last_error() if the offset didn't correspond to the begin of a valid UTF-8 code point (only when running a regex in UTF-8 mode). Available since PHP 5.3.0.\n";
          break;
          case
PCRE_VERSION:
          print
"PCRE version and release date (e.g. '7.0 18-Dec-2006'). Available since PHP 5.2.4.\n";
          break;
    }
}
?>

> <リソース型
Last updated: Fri, 13 Nov 2009
 
 
show source | credits | sitemap | contact | advertising | mirror sites