相關(guān)關(guān)鍵詞
關(guān)于我們
最新文章
php中str_pad()函數(shù)用法分析
本文實例講述了php中str_pad()
函數(shù)用法。分享給大家供大家參考,具體如下:
str_pad()
函數(shù)把字符串填充為新的長度。
語法:
str_pad(string,ength,pad_string,pad_type);
參數(shù)列表:
參數(shù) | 描述 |
---|---|
string | 必需。規(guī)定要填充的字符串。 |
length | 必需。規(guī)定新的字符串長度。如果該值小于字符串的原始長度,則不進行任何操作。 |
pad_string | 可選。規(guī)定供填充使用的字符串。默認是空白。 |
pad_type | 可選。規(guī)定填充字符串的哪邊??赡艿闹担篠TR_PAD_BOTH - 填充字符串的兩側(cè)。如果不是偶數(shù),則右側(cè)獲得額外的填充。STR_PAD_LEFT - 填充字符串的左側(cè)。STR_PAD_RIGHT - 填充字符串的右側(cè)。默認。 |
For example:
class test{ private $var; public function __construct($var){ $this->var=$var; } public function test(){ $result=str_pad($this->var,30,"*"); return $result; } } $T=new test("hello"); $result=$T->test(); echo $result;