php str_pad 函数使用详解

yipeiwu_com6年前PHP代码库
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在字符断点处截断文字的实现代码

复制代码 代码如下: //所谓断字 (word break),即一个单词可在转行时断开的地方。这一函数将在断字处截断字符串。 // Please acknowledge use of t...

php断点续传之如何分割合并文件

复制代码 代码如下: <?php ini_set("memory_limit", "50M");//必须的,根据你环境的实际情况尽量大,防止报错 ini_set("max_exec...

php curl 获取https请求的2种方法

今天一个同事反映,使用curl发起https请求的时候报错:“SSL certificate problem, verify that the CA cert is OK. Detail...

一些PHP Coding Tips(php小技巧)[2011/04/02最后更新]

最后更新: 2011/04/02 1. 使用list来实现一次获取explode后的特定段值: list( , $mid) = explode(';', $string); 2. 使用N...

php中实现进程锁与多进程的方法

php中实现进程锁与多进程的方法

为什么需要进程锁? 主要作用就是防止你重复执行同一程序,主要用在crontab中,当你设置了一个定时任务,然后每分钟执行一次,如果不加进程锁的话,之前的进程没有执行完的情况下。每分钟都会...