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.:.:
Statement
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
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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article
Assassin's Creed Shadows: Seashell Riddle Solution
3 weeks agoByDDD
What's New in Windows 11 KB5054979 & How to Fix Update Issues
2 weeks agoByDDD
Where to find the Crane Control Keycard in Atomfall
3 weeks agoByDDD
Assassin's Creed Shadows - How To Find The Blacksmith And Unlock Weapon And Armour Customisation
1 months agoByDDD
Roblox: Dead Rails - How To Complete Every Challenge
3 weeks agoByDDD

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Linux new version
SublimeText3 Linux latest version

Dreamweaver CS6
Visual web development tools