php 截取字符串并以零补齐str_pad 函数

WBOY
Release: 2016-07-29 08:45:08
Original
1147 people have browsed it

定义和用法
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.:.:

以上就介绍了 php 截取字符串并以零补齐str_pad 函数,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Related labels:
source:php.cn
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 [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!