php 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);
复制代码 代码如下:

<?php
$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_"
?>

« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3