Home > Backend Development > PHP Tutorial > Detailed explanation of the use of php str_pad function_PHP tutorial

Detailed explanation of the use of php str_pad function_PHP tutorial

WBOY
Release: 2016-07-21 15:47:49
Original
1197 people have browsed it

string str_pad (string, int pad_length, string pad_string, int pad_type);
string specifies the string, pad_length specifies the length, pad_string is used to fill the string (optional parameter), pad_type specifies the padding position (optional parameter, STR_PAD_LEFT ,STR_PAD_BOTH);
If pad_string and pad_type are both empty, it means that the default pad_string is a space, and pad_type is automatically filled at the end of the specified string.

Copy codeThe code is as follows:

$string = "test";
echo str_pad($string, 10); // produces "test ";
?>

The remaining two examples:
Copy the code The code is as follows:

$string = "test";
echo str_pad($string , 10,'+',STR_PAD_LEFT); // produces "++++++test";
?>

Copy code The code is as follows:

$string = "test" ;
echo str_pad($string , 10,'+',STR_PAD_BOTH); // produces "+++test+++";
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/319831.htmlTechArticlestring str_pad ( string , int pad_length , string pad_string , int pad_type); string specifies the string, pad_length specifies the length, pad_string is the string used to fill (optional parameter), pad_type refers to...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template