1

私はちょっとここで立ち往生しています。11桁の数字を見つけるためにいくつかのpregコーディングを行いましたが、「preg --time()」のような関数に見つかった/一致したものを使用する方法がわかりません。

注意:11桁は複数回検出される可能性があるため、関数はそれらのいずれか、おそらく配列のループなどで使用できるようにする必要がありますか?

"#\d{11}#"   -   Quick example on the preg i might will use.

ヘルプ!

4

2 に答える 2

2

preg_replace_callbackカスタム関数を使用して、各一致に変更を加えるために使用します。

function your_custom_function($matches){
    $match = $matches[0];
    // Do something with $match
    return $match;
}
$string = preg_replace_callback(
    "#\d{11}#",
    "your_custom_function",
    $string
);
于 2012-09-17T20:13:28.310 に答える
0

preg_replaceは自動的にすべてを置き換え、preg_match_allは3番目のパラメーターのすべての一致を提供します。

preg_match("/\d{11}/", "Quick example on the preg I might will use", $matches);
print_r($matches);
于 2012-09-17T20:08:09.623 に答える