Where The Streets Have No Name

number_format() 본문

Developement/PHP

number_format()

highheat 2006. 6. 27. 15:52
톡박에 올리다가 tip&tech에서 검색해보니 정규식으로 된건 없는듯해서 올려봅니다.

[javascript]
<script language='javascript'>
String.prototype.number_format=function(){
return this.replace(/(d)(?=(?:d{3})+(?!d))/g,'$1,');
}

var test1='aaaaS1111aaaaaa';
document.write(test1.number_format());
//aaaaS1,111aaaaaa
</script>

[php]
<?
function new_number_format($str){
return preg_replace("/(?<=d)(?=(?:d{3})+(?!d))/",',',$str);
}
echo new_number_format('aaaaS1111aaaaaa');
//aaaaS1,111aaaaaa
?>