php intercepts a string and complements the str_pad of function with zero

  • 2020-05-05 11:01:43
  • OfStack

Definition and usage of
The str_pad() function populates the string to the specified length.

Grammar
The str_pad(string,length,pad_string,pad_type) parameter describes
string required. Specifies the string to fill.
length required. Specifies the length of the new string. If the value is less than the length of the original string, nothing is done.
pad_string optional. Specifies the string to use for padding. The default is blank.
pad_type optional. Specifies the side of the fill string.

Possible values:

STR_PAD_BOTH - fills both ends of the string. If it is not even, the right side gets extra padding.
STR_PAD_LEFT - fills the left side of the string.
STR_PAD_RIGHT - fills to the right of the string. This is the default.


Example 1
< ?php
$str = "//www.jb51.net";
echo str_pad($str,30,".");
? >

Output:

//www.jb51.net........

Example 2
< ?php
$str = "//www.jb51.net";
echo str_pad($str,30,".",STR_PAD_LEFT);
? >

Output:

........//www.jb51.net

Example 3
< ?php
$str = "//www.jb51.net";
echo str_pad($str,30,".:",STR_PAD_BOTH);
? >

Output:

.:.://www.jb51.net.:.:

Related articles: