<?php function num3($num){ preg_match_all("|[0-9]{1}|",$num,$getnum); $number = count($getnum[0])-1; $j = 1; $varchar = ""; for($i=$number;$i>=0;$i--){ if($j%3){ $varchar = $getnum[0][$i].$varchar; }else{ $varchar = $getnum[0][$i].$varchar; $varchar = ",".$varchar; } $j++; } return $varchar; } echo num3("1000221"); ?>