加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php str_pad 函数使用详解

发布时间:2020-12-13 05:30:02 所属栏目: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均为空,那么

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就是自动填充在指定字符串的末端.
<div class="codetitle"><a style="CURSOR: pointer" data="90020" class="copybut" id="copybut90020" onclick="doCopy('code90020')"> 代码如下:<div class="codebody" id="code90020">
<?
$string = "test";
echo str_pad($string,10); // produces "test ";
?>

其余两个例子:
<div class="codetitle"><a style="CURSOR: pointer" data="81734" class="copybut" id="copybut81734" onclick="doCopy('code81734')"> 代码如下:<div class="codebody" id="code81734">
<?
$string = "test";
echo str_pad($string,10,'+',STR_PAD_LEFT); // produces "++++++test";
?>

<div class="codetitle"><a style="CURSOR: pointer" data="59708" class="copybut" id="copybut59708" onclick="doCopy('code59708')"> 代码如下:<div class="codebody" id="code59708">
<?
$string = "test";
echo str_pad($string,STR_PAD_BOTH); // produces "+++test+++";
?>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读