Why this example wont work:
$string='1000000000000';
while($string=preg_replace('/(\d)((\d\d\d)+\b)/','$1,$2',$string)){}
echo $string."<br>";
It supposed that the loop is repeated untill is not more to match. Untill the regex fail. But no, the loop is never ending.
this alternative works:
$string='10000000000000';
while(preg_match("/(\d)((\d\d\d)+\b)/",$string)){
$string=preg_replace("/(\d)((\d\d\d)+\b)/","$1,$2",$string);
}
echo $string."<br>";
My question is: the preg_replace function returns some TRUE/FALSE value when the regex can't still matching? If return False why in the first example the loop never stop. Ive tried with:
while((regex)!==FALSE)
while((regex)==TRUE)
and it dont work.
I dont care about the how to put commas, i wanna know about the preg_replace function
If someone can help me. would be great. thanks