我是靠谱客的博主 饱满月亮,这篇文章主要介绍php str_pad 函数使用详解,现在分享给大家,希望可以做个参考。

string str_pad ( string , int pad_length , string pad_string , int pad_type);
string 指定字符串,pad_length指定长度,pad_string用来填充的字符串(可选参数),pad_type指定填充位置(可选参数,STR_PAD_LEFT,STR_PAD_BOTH);
如果pad_string , pad_type均为空,那么就等于默认pad_string 为空格, pad_type就是自动填充在指定字符串的末端.

复制代码 代码如下:

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

其余两个例子:
复制代码 代码如下:

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

复制代码 代码如下:

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

最后

以上就是饱满月亮最近收集整理的关于php str_pad 函数使用详解的全部内容,更多相关php内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(142)

评论列表共有 0 条评论

立即
投稿
返回
顶部