强制最少3位数?

时间:2014-07-15 11:12:26

标签: php sql

我想知道是否有可能始终强制从SQL语句到PHP的最少三位数,我对PHP / SQL来说是个新的。

$count = $con->num_rows #num_rows currently shows 1
echo "Number of Rows: " .$count #shows "Number of Rows: 1"

如何强制它输出“行数:001”。 但是一旦它进入自然的四位数字1000,那么它就不会强制三位数。

示例:001 010 100 1000

感谢您的帮助!

3 个答案:

答案 0 :(得分:5)

  str_pad ( $count, 3, "0", STR_PAD_LEFT)

答案 1 :(得分:0)

     $newstring = str_pad($string,3,"0",STR_PAD_LEFT);

答案 2 :(得分:0)

  

str_pad - 用另一个字符串将字符串填充到一定长度

     

string str_pad(string $ input,int $ pad_length [,string $ pad_string ="" [,int $ pad_type = STR_PAD_RIGHT]])

以及更多

http://php.net/manual/en/function.str-pad.php就是您所需要的。