php 截取字符串并以零补齐str_pad() 函数
str_pad() 函数把字符串填充为指定的长度,需要的朋友可以参考下。
定义和用法
str_pad() 函数把字符串填充为指定的长度。
语法
str_pad(string,length,pad_string,pad_type)参数 描述
string 必需。规定要填充的字符串。
length 必需。规定新字符串的长度。如果该值小于原始字符串的长度,则不进行任何操作。
pad_string 可选。规定供填充使用的字符串。默认是空白。
pad_type 可选。规定填充字符串的那边。
可能的值:
STR_PAD_BOTH - 填充到字符串的两头。如果不是偶数,则右侧获得额外的填充。
STR_PAD_LEFT - 填充到字符串的左侧。
STR_PAD_RIGHT - 填充到字符串的右侧。这是默认的。
例子 1
$str = "http://www.jb51.net";
echo str_pad($str,30,".");
?>
输出:
http://www.jb51.net........
例子 2
$str = "http://www.jb51.net";
echo str_pad($str,30,".",STR_PAD_LEFT);
?>
输出:
........http://www.jb51.net
例子 3
$str = "http://www.jb51.net";
echo str_pad($str,30,".:",STR_PAD_BOTH);
?>
输出:
.:.:http://www.jb51.net.:.:

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Go language is a powerful and flexible programming language that provides rich string processing functions, including string interception. In the Go language, we can use slices to intercept strings. Next, we will introduce in detail how to intercept strings in Go language, with specific code examples. 1. Use slicing to intercept a string. In the Go language, you can use slicing expressions to intercept a part of a string. The syntax of slice expression is as follows: slice:=str[start:end]where, s

Interception method: 1. Intercept a single character, the syntax is "string[index]", where "string" represents the source string, and "index" represents the character subscript to be obtained; 2. Intercept a substring, the syntax is "string[start: end" ]", where "start" represents the index of the first character to be intercepted (including this character when intercepting), "end" represents the index of the last character to be intercepted (excluding this character); 3. Get the entire String, syntax "string[:]".

How to use the LEFT function in MySQL to intercept the left part of a string. In database management systems, we often encounter situations where we need to intercept a certain part from a string. MySQL provides many built-in string functions, including the LEFT function, which can be used to intercept the left part of a string. The syntax of the LEFT function is as follows: LEFT (str, length) where str is the string to be intercepted and length is the length to be intercepted. Next, we will use code examples to demonstrate how

Use MySQL's LEFT function to intercept the specified length of a string. In MySQL, we often need to intercept strings to meet specific needs. Among them, the LEFT function is a very practical function that can intercept the specified length of a string. This article will introduce how to use MySQL's LEFT function to intercept strings and give code examples. First, we need to understand the syntax of the LEFT function. The basic syntax of the LEFT function is as follows: LEFT(string,lengt

The substr() function in PHP: How to intercept part of a string requires specific code examples. In PHP programming, string processing is one of the most common operations. Intercepting part of a string is a requirement that is often encountered when processing strings. In PHP, we can use the built-in substr() function to intercept part of a string. This article will introduce the usage of substr() function in detail and give specific code examples. The basic usage of the substr() function is as follows: string

How to use the RIGHT function in MySQL to intercept the right part of a string. In MySQL, the RIGHT function is a function used to intercept the right part of a string. It accepts two parameters: the string to be intercepted and the length to be intercepted, and returns a string containing the specified length. Use the RIGHT function to get the right part of a string very conveniently. Below we will demonstrate how to use the RIGHT function through code examples. First, we need to create a sample data table to store the strings to be intercepted. CR

Use the PHP function "str_pad" to fill the left or right side of a string with a specified string. When writing PHP code, we often need to process strings. Sometimes, we need to pad a string to a specified length. At this time, we can use PHP's built-in function "str_pad" to complete this task. The "str_pad" function pads a specified string on the left or right side of the string to a specified length. The basic syntax of the "str_pad" function is as follows: string

js uses the substring() method, the slice() method, the substr() method and the split() method to intercept strings. Detailed introduction: 1. The substring() method accepts two parameters, namely the starting position and the end position; 2. The slice() method allows the use of negative numbers as parameters, indicating that the index is calculated from the end of the string; 3. substr( ) method, which accepts two parameters, namely the starting position and the number of characters to be intercepted; 4. split() method, etc.
