PCRE関数 2016年10月04日 13:32   編集
正規表現検索および置換を行う
preg_replace ( 検索パターン(文字列か配列) , 置換パターン(文字列か配列) , 置換対象(文字列か配列) [, 置換最大回数(int) [, 置換回数 ]] )

置換回数を使う場合は初期値を設定しておかないとエラーになる。
またその前の置換最大回数も空白のままだとエラーになる。
デフォルトの-1(無制限)などを指定する必要がある。
$str = 'a12bcd345ef6789gh01ij';
$count = 0;
$str2 = preg_replace( '/\d{3,}+/' , '□' , $str , -1 , $count );
print "\$str2=$str2\n";
print "\$count=$count\n";
実行結果
$str2=a12bcd□ef□gh01ij
$count=2
counter:2,923