Analysis of str_pad () function usage in php, phpstr_pad

Source: Internet
Author: User
Tags php online

Analysis of str_pad () function usage in php, phpstr_pad

This example describesstr_pad()Function usage. We will share this with you for your reference. The details are as follows:

str_pad()FunctionFill the string with a 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. Specify the length of the new string. If the value is smaller than the original length of the string, no operation is performed.
Pad_string Optional. The specified string for filling. The default value is blank.
Pad_type Optional. Specifies the side of the string to be filled. Possible value: STR_PAD_BOTH-fill both sides of the string. If it is not an even number, the right side will receive additional filling. STR_PAD_LEFT-fill the left side of the string. STR_PAD_RIGHT-fill the right side of the string. Default value.

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*************************

PS: here we will provide you with a related php function table for your reference:

Php online function reference table:
Http://tools.jb51.net/table/php_fun_table

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.