Hatena::ブログ(Diary)

万年素人からGeekへの道 このページをアンテナに追加 RSSフィード Twitter

□僕のAndroidアプリ □NGUI翻訳 □僕の翻訳した本 □僕のChrome拡張 □ひな祭りFacebookアプリ □タワーディフェンスゲーム! □お薦めアプリ

2012-04-27 Friday このエントリーを含むブックマーク このエントリーのブックマークコメント

PHPドキュメントわかりづらい

http://jp.php.net/manual/ja/function.preg-match.php

・1の例

$subject = "abcdef";
$pattern = '/^def/';
preg_match($pattern, $subject, $matches, PREG_OFFSET_CAPTURE, 3);
print_r($matches);

こちらが

Array

(

)

になり、

・2の例

$subject = "abcdef";
$pattern = '/^def/';
preg_match($pattern, substr($subject,3), $matches, PREG_OFFSET_CAPTURE);
print_r($matches);

Array
(
    [0] => Array
        (
            [0] => def
            [1] => 0
        )

)

な理由。


abcdefは

|a|b|c|d|e|f|

|0|1|2|3|4|5|