Fill 0 on the left of the PHP string, 0 on the right of the string, and a php string

Source: Internet
Author: User

Fill 0 on the left of the PHP string, 0 on the right of the string, and a php string

Overview: A project usually uses automatic filling on the left, right, or even middle of a string of encoding to specify the length of the filled string, for example, "0.

Str_pad: This function returnsInputResult of being filled to the specified length from the left, right, or simultaneously.

 

This may not be clear. Let's look at a case:

Str_pda ('supplemented string', 'length of supplemented string', 'character supplemented ', 'str _ PAD ...');

STR_PAD_LEFT: Fill in on the left

STR_PAD_RIGHT: Fill in on the right

STR_PAD_BOTH: complement on both sides

 

<? Php $ code = str_pad ('pq ', 11,0, STR_PAD_LEFT); echo $ code;

Output result:

'000000000pq'(Length = 11)

 

If you have any questions or want to add them, please leave a message.

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.