From: http://blog.163.com/dingjie_china/blog/static/1228662992011626115229455/
You can use either of the following methods to output a string of a certain length.PHP string auto-filling and auto-completion.
Method 1:
$ Newstr = sprintf ('% 05s', $ Str );
Sprintf () is very flexible. In the preceding format string,% 05 s"Indicates the output is a string of 5 characters. If the length is insufficient, the left side is supplemented with zero. If it is written as"% 5sBy default, space is used for completion. If you want to use other characters for completion, you must add a single quotation mark before the character, that is, in the form of"% '#5 S"Indicates completion by the well number. Finally, If you want completion to happen on the right side of the string, add the minus sign after the percent sign."%-05 s".
Method 2:
$ Cd_no = str_pad (++ $ next_cd_no, 8, '#', str_pad_left );
Str_pad (string, length, pad_string, pad_type): For detailed usage, see the manual.
String is required. Specifies the string to be filled.
Length is required. Specify the length of the new string. If the value is smaller than the length of the original string, no operation is performed.
Pad_string is optional. The specified string for filling. The default value is blank.
Pad_type is optional. Specify the other side of the string to be filled.
These two methods are easy to implement.PHP string auto-completionFunction.