PHP Str_pad () fills a string into a string of the specified length _php tips

Source: Internet
Author: User
/**
* Fills a string into a string of a specified length (multibyte security)
* @param string $str Specify the filled strings
* @param int $len Specifies the length of the filled string, not if the value is negative or less than the length of the string
* @param string $pad _str the strings to be filled
* @param int $pad _type The direction of the specified fill Str_pad_right,str_pad_left or Str_pad_both
* @return String
*/

String Str_pad (string $str, int $len, String $pad _str, String $pad _type);

Echo Str_pad ($result 2[0],6, "0", str_pad_left);
Copy Code code as follows:

<?php
$input = "Alien";
Echo Str_pad ($input, 10); Produces "Alien"
Echo Str_pad ($input, ten, "=", str_pad_left); Produces "-=-=-alien"
Echo Str_pad ($input, "_", Str_pad_both); Produces "__alien___"
Echo Str_pad ($input, 6, "___"); Produces "Alien_"
?>

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.