Pad-"is the abbreviation of padding.
There are two functions in PHP -- at least two functions are available. I don't know if there are any other functions. The following details can be implemented: str_pad () and sprintf ().
Str_pad
As the name suggests, this function is for strings. This function can fill any other strings with the specified string.
Example: str_pad (string with padding, the length after filling, the string to fill, and the position to fill)
The length after filling must be a positive integer and there are three options to fill the position,
Left: str_pad_left,
Right: str_pad_right,
Two ends: str_pad_both
For example:
1 |
echo str_pad (1,8,”0″,STR_PAD_LEFT); |
Result: 00000001
1 |
echo str_pad (1,8,”0″,STR_PAD_RIGHT); |
Result: 10000000
1 |
echo str_pad (1,8,”0″,STR_PAD_BOTH); |
Result: 00010000
In the above example, it is worth noting that if the number of digits to be filled is an odd number, for example, if the number of digits to be filled is 7 in the third case, the right side is given priority.
There is also a function like this in the array, which is array_pad. Use another str_pad method.
Basically the same
About pad Functions