PHP add 0 to front or back

Source: Internet
Author: User

I believe you must have encountered such a problem, because PHP is a weak type, so when sorting, sometimes very stomach pain

So here we need to unify the number of bits to handle it.

Usually adds 0 to the end to complement

Method 1: str_pad- fills the string with another string for the specified length

The function returns input The result of being filled from the left, right, or both ends to the length of the set.

$input = ' 11111 ';

echo str_pad ( $input , 10< Span style= "color: #007700;" >, ' 0 ' , str_pad_ Left

The result of this output is:

1111100000

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.