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分页类的代码

下面看这一段代码: PHP 复制代码 代码如下: <? /** * filename: ext_page.class.php * @package:phpbean * @autho...

写php分页时出现的Fatal error的解决方法

Fatal error: Cannot redeclare htmtocode() (previously declared in D:\www_local\mytest\conn.ph...

PHP时间格式控制符对照表分享

format 字符 说明 返回值例子 日 --- --- d 月份中的第几天,有前导零的 2 位数字 01 到 31 j 月份中的第几天,没有前导零 1 到 31 S 每...

php class中self,parent,this的区别以及实例介绍

一,this 1,要用this,你必有是一个对像的形势,不然它会报错的,Fatal error: Using $this when not in object context。2,th...

thinkphp3.2点击刷新生成验证码

thinkphp3.2点击刷新生成验证码

再介绍thinkphp3.2验证码的使用方法之前,先为大家详细介绍ThinkPHP 验证码,具体内容如下 ThinkPHP 内置了验证码的支持,可以直接使用。要使用验证码,需要导入扩展类...