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+++";
?>

相关文章

利用discuz实现PHP大文件上传应用实例代码

对于确实需要改善论坛附件上传条件的朋友可以尝试将上面提及的参数在php.ini进行设置,以适应大文件上传的需要。同时别忘记在论坛的后台相应做附件限制的地方进行设置。 论坛主要有2个地方...

PHP中创建空文件的代码[file_put_contents vs touch]

I has passed a small test to check which function is faster to create a new file. file_put_co...

重新封装zend_soap实现http连接安全认证的php代码

复制代码 代码如下: <?php class MyFramework_Soap_server extends Zend_Soap_Server { protected $_logi...

php实现俄罗斯乘法实例

本文实例讲述了php实现俄罗斯乘法的方法。分享给大家供大家参考。具体分析如下: 一、概述: 俄罗斯乘法是一种计算两数相乘的算法。 举例如下: 计算 35*72 过程 35 72 17 1...

php使用curl获取https请求的方法

本文实例讲述了php使用curl获取https请求的方法。分享给大家供大家参考。具体分析如下: 今日在做一个项目,需要curl获取第三方的API,对方的API是https方式的。 之前使...