Home Backend Development PHP Tutorial String constant php str_pad fills the string into a string of specified length

String constant php str_pad fills the string into a string of specified length

Jul 29, 2016 am 08:42 AM
String constant

/**
* Pad the string into a string of specified length (multi-byte safe)
* @param string $str specifies the filled string
* @param int $len specifies the length of the filled string, if the value is Negative number or less than the length of the string will not be filled
* @param string $pad_str The string to be filled
* @param int $pad_type Specifies the direction of filling 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($result2[0],6,"0",STR_PAD_LEFT);

Copy code The code is as follows:


$input = "Alien";
echo str_pad($input, 10); // produces "Alien "
echo str_pad($input, 10 , "-=", STR_PAD_LEFT); // produces "-=-=-Alien"
echo str_pad($input, 10, "_", STR_PAD_BOTH); // produces "__Alien___"
echo str_pad($input, 6 , "___"); // produces "Alien_"
?>

The above introduces the string constant php str_pad to fill the string into a string of specified length, including the content of string constants. I hope it will be helpful to friends who are interested in PHP tutorials.

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What are string constants in sql What are string constants in sql May 08, 2024 am 09:54 AM

String constants in SQL are special values ​​used to represent text data, enclosed in single quotes (') or double quotes ("), and can contain any characters. They are of two types: single quoted string constants and double quotes String constants are widely used in condition specification, data provision, derived column creation and function parameters. Single quotes are usually used, but double quotes can contain single quote characters and span multiple lines.

What are the representation methods of string constants? What are the representation methods of string constants? Dec 26, 2023 am 10:20 AM

Representation methods of string constants: 1. Use quotation marks; 2. Escape characters; 3. Multi-line strings; 4. Original strings; 5. String concatenation; 6. String literals and objects; 7. Encoding question. Detailed introduction: 1. Use quotation marks. In most programming languages, string constants are usually enclosed in double quotes or single quotes; 2. Escape characters. In string constants, sometimes it is necessary to represent some special characters, such as newline characters. , tab, or backslash itself, characters that cannot be typed directly can be represented by escape sequences, etc.

Usage of single quotes and double quotes in c language Usage of single quotes and double quotes in c language May 02, 2024 pm 02:36 PM

Summary: Single quotes and double quotes in C language are used to define string constants. Single quotes define a character array with a limited length, which is stored in the data area and can be modified; double quotes define a string constant that is stored in the code area and has a limited length. Restricted, cannot be modified, may contain escape characters.

An in-depth exploration of the inner workings of the JVM: a detailed analysis from memory processing to garbage collection An in-depth exploration of the inner workings of the JVM: a detailed analysis from memory processing to garbage collection Feb 18, 2024 pm 10:41 PM

Understanding JVM principles: a comprehensive analysis from memory management to garbage collection. With the widespread application of the Java language, the Java Virtual Machine (JVM) has become an important environment for Java program execution. Understanding JVM principles is very important for Java developers, which can help programmers optimize code and adjust performance. This article will comprehensively analyze the JVM's memory management and garbage collection mechanism, and provide specific code examples to help readers better understand. JVM Overview JVM is one of the core components of Java program execution. It is responsible for

What are numerical constants in C language? What are numerical constants in C language? Apr 29, 2024 pm 05:33 PM

Numeric constants in C language represent fixed values ​​and cannot be modified. The main types include integers, floating point, characters and strings. Constants improve readability, reduce errors, and optimize code.

PHP returns the ASCII value of the first character of the string PHP returns the ASCII value of the first character of the string Mar 21, 2024 am 11:01 AM

This article will explain in detail the ASCII value of the first character of the string returned by PHP. The editor thinks it is very practical, so I share it with you as a reference. I hope you can gain something after reading this article. PHP returns the ASCII value of the first character of a string Introduction In PHP, getting the ASCII value of the first character of a string is a common operation that involves basic knowledge of string processing and character encoding. ASCII values ​​are used to represent the numeric value of characters in computer systems and are critical for character comparison, data transmission and storage. The process of getting the ASCII value of the first character of a string involves the following steps: Get String: Determine the string for which you want to get the ASCII value. It can be a variable or a string constant

What are legal constants in C language? What are legal constants in C language? Apr 13, 2024 pm 07:12 PM

In C, a legal constant must be of an unambiguous type: integer, floating point, or character. Value is valid: within type range. No side effects: the value does not depend on program execution. Representations include: integers, floating point, characters, string constants, and escape sequences.

What does \0 mean in c++ What does \0 mean in c++ May 09, 2024 am 04:21 AM

In C++, "\0" represents the null character or null terminator, with a value of 0. It is used to indicate the end of a string, making it easier for the compiler and program to identify the boundaries of the string.

See all articles