例如,我想在一个数字的每3位数字中加上逗号.
$number = 1234567;
// should print 1,234,567
我怎样才能做到这一点?
更新:请看这个代码
/**
* 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;
}
在此返回只有3位数.