php中str_pad()函数用法的详细介绍

黄舟
Release: 2023-03-07 07:08:02
Original
1769 people have browsed it

这篇文章主要介绍了phpstr_pad()函数用法,较为详细的分析了php中str_pad()函数的功能、参数含义及具体使用方法,需要的朋友可以参考下

本文实例讲述了php中str_pad()函数用法。分享给大家供大家参考,具体如下:

str_pad() 函数字符串填充为新的长度

语法:

str_pad(string,ength,pad_string,pad_type);

参数列表:

参数描述
string必需。规定要填充的字符串。
length必需。规定新的字符串长度。如果该值小于字符串的原始长度,则不进行任何操作。
pad_string可选。规定供填充使用的字符串。默认是空白。
pad_type可选。规定填充字符串的哪边。可能的值:STR_PAD_BOTH - 填充字符串的两侧。如果不是偶数,则右侧获得额外的填充。STR_PAD_LEFT - 填充字符串的左侧。STR_PAD_RIGHT - 填充字符串的右侧。默认。


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;
Copy after login

output:

hello*************************
Copy after login

The above is the detailed content of php中str_pad()函数用法的详细介绍. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!