本文實例講述了php中str_pad()函數(shù)用法。分享給大家供大家參考,具體如下:
	str_pad() 函數(shù)把字符串填充為新的長度。
語法:
	str_pad(string,ength,pad_string,pad_type);
參數(shù)列表:
| 參數(shù) | 描述 | 
|---|---|
| string | 必需。規(guī)定要填充的字符串。 | 
| length | 必需。規(guī)定新的字符串長度。如果該值小于字符串的原始長度,則不進(jìn)行任何操作。 | 
| pad_string | 可選。規(guī)定供填充使用的字符串。默認(rèn)是空白。 | 
| pad_type | 可選。規(guī)定填充字符串的哪邊。可能的值:STR_PAD_BOTH - 填充字符串的兩側(cè)。如果不是偶數(shù),則右側(cè)獲得額外的填充。STR_PAD_LEFT - 填充字符串的左側(cè)。STR_PAD_RIGHT - 填充字符串的右側(cè)。默認(rèn)。 | 
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;output:
hello*************************
希望本文所述對大家PHP程序設(shè)計有所幫助。
新聞熱點
疑難解答
圖片精選