php str_pad() 将字符串填充成指定长度的字符串_php技巧

WBOY
Release: 2016-05-17 09:27:38
Original
1166 people have browsed it

/**
* 将字符串填充成指定长度的字符串(多字节安全)
* @param string $str 指定被填充的字符串
* @param int $len 指定被填充的字符串的长度,如果值为负数或小于字符串的长度则不填充
* @param string $pad_str 要填充的字符串
* @param int $pad_type 指定填充的方向STR_PAD_RIGHT,STR_PAD_LEFT或STR_PAD_BOTH
* @return string
*/

// string str_pad(string $str, int $len, string $pad_str, string $pad_type);

echo str_pad($result2[0],6,"0",STR_PAD_LEFT);

复制代码 代码如下:

$input = "Alien";
echo str_pad($input, 10); // produces "Alien "
echo str_pad($input, 10, "-=", STR_PAD_LEFT); // produces "-=-=-Alien"
echo str_pad($input, 10, "_", STR_PAD_BOTH); // produces "__Alien___"
echo str_pad($input, 6 , "___"); // produces "Alien_"
?>
Related labels:
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