str_pad() 将字符串填充成指定长度的字符串的用法。
/**
* 将字符串填充成指定长度的字符串(多字节安全)
* @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_"
?>
Statement: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