Home > Backend Development > PHP Tutorial > Detailed explanation of the usage of str_pad() function in php

Detailed explanation of the usage of str_pad() function in php

墨辰丷
Release: 2023-03-27 19:34:02
Original
2096 people have browsed it

This article mainly introduces the usage of str_pad() function in php. It analyzes the function, parameter meaning and specific usage method of str_pad() function in php in more detail. Friends who need it can refer to it

The example in this article describes the usage of str_pad() function in php. Share it with everyone for your reference, the details are as follows:

str_pad() Function fills the string with the new length.

Syntax:

str_pad(string,ength,pad_string,pad_type);

Parameter list:


Parameters Description
string Required. Specifies the string to be filled.
length Required. Specifies the new string length. If the value is less than the original length of the string, no operation is performed.
pad_string Optional. Specifies the string used for padding. The default is blank.
pad_type Optional. Specifies which side of the string to fill. Possible values: STR_PAD_BOTH - Pad both sides of the string. If it's not an even number, the right side gets extra padding. STR_PAD_LEFT - pad the left side of the string. STR_PAD_RIGHT - Pad the right side of the string. default.


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 entire content of this article, I hope it will be helpful to everyone's study.


Related recommendations:

php fills the string with a new length functionstr_pad()

php str_pad()Introduction to the usage of the function

str_pad()## in php #Detailed explanation of function usage examples

The above is the detailed content of Detailed explanation of the usage of str_pad() function in php. 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 admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template