把逗号放在PHP数字变量中

时间:2015-01-11 08:55:03

标签: php html mysql sql

我在header.php中使用了一个脚本来显示注册了多少用户(例如它说的是79447个玩家),但是我想让它说79,447个玩家。我该如何添加逗号?我尝试了一些方法但失败了。

<?php
include('session.php');
?>

<style>
.navbar {
    font-family: 'Numans', sans-serif;
    text-transform: uppercase;
}
.navbar-inverse {
    background: #00aa00;
}
.dropdown-menu li a:hover, .dropdown-menu-default li a:hover {
    color: #00aa00;
}
.dropdown-menu {
min-width: 100%;
border-radius: 0px;
}
.navbar .navbar-form .form-control-wrapper .form-control, .navbar .navbar-form .form-control {
    text-transform: uppercase;
}
.nav>li>a>img {
    max-width: 20px;
    margin-right: 4px;
}
</style>

<div class="navbar navbar-inverse">
    <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-inverse-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
        </button>
        <a class="navbar-brand" href="https://epicmc.us">EPICMC</a>
    </div>
    <div class="navbar-collapse collapse navbar-inverse-collapse">
        <ul class="nav navbar-nav">
            <li><a href="https://epicmc.us/">HOME</a></li>
            <?php $remote_api = file_get_contents('http://epicmc.us/api.php?task=total'); $remote_job = json_decode($remote_api); echo '<li>'; echo '<a href="javascript:void(0)">'; echo substr($remote_job->amount,0,75); ?> PLAYERS</li></a>
            <li class="dropdown">
                </ul>
            </li>
        </ul>
        <form class="navbar-form navbar-left" action ="stats.php" method="GET"><input type="text" name="player" class="form-control col-lg-8" autocomplete="off" placeholder="USERNAME"></form>
        <ul class="nav navbar-nav navbar-right">
            <li class="dropdown">
                <a href="javascript:void(0)" class="dropdown-toggle" data-toggle="dropdown">
                <img src="https://minepic.org/avatar/20/<?php echo strtoupper($_SESSION['login_user']); ?>">
                <?php if(isset($_SESSION['login_user'])){
                echo "HOWDY, ";
                echo strtoupper($_SESSION['login_user']);
                } else {
                Echo "HOWDY, GUEST";
                }?><b class="caret"></b></a>
                <ul class="dropdown-menu">
                <?php if(isset($_SESSION['login_user'])){
                echo '<li><a href="https://epicmc.us/login.php">ACCOUNT</a></li>';
                echo '<li><a href="#">NOTIFICATIONS <span class="badge">0</span></a></li>';
                echo '<li><a href="https://epicmc.us/logout.php">LOGOUT</a></li>';
                } else {
                echo '<li><a href="https://epicmc.us/login.php">LOGIN</a></li>';
                }?>
              </ul>
            </li>
        </ul>
    </div>
</div>

1 个答案:

答案 0 :(得分:2)

从代码片段看,用户数量在变量$remote_job->amount

echo number_format($remote_job->amount);

http://php.net/manual/en/function.number-format.php