how to put comma in every 3 digit for a number

php

Solution

Use

echo number_format('1234567');

PHP Manual : number_format()

Problem

I want to put comma in every 3 digit for a number, for example. ``` $number = 1234567; // should print 1,234,567 ``` how can I do this? update: please see this code ``` <?php /** * Get Popularity Text of a Domain via Alexa XML Data * * @return string|FALSE text or FALSE on error */ function alexa_get_rank($domain) { $alexa = "http://data.alexa.com/data?cli=10&dat=s&url=%s"; $request_url = sprintf($alexa, urlencode($domain)); $xml = simplexml_load_file($request_url); if (!$xml) { return FALSE; } $nodeAttributes = $xml->SD[1]->POPULARITY->attributes(); $text = (int) $nodeAttributes['TEXT']; $num = number_format($text); return $num; } ``` in this return only 3 digit.

Original source