px普贤教程PuXian
普贤教程 › 包参考

strpad 包

字符串填充与重复(PHP str_pad / str_repeat / str_truncate)

strpad.px — 字符串填充与重复(PHP str_pad / str_repeat / str_truncate)

项值
包名strpad
版本0.1.0
入口strpad.px
分类文本与中文处理
文件数 / 行数1 / 77

安装与引入

bash
pxpkg init          # 首次
pxpkg add strpad@0.1.0
pxpkg install
px
import strpad
所属分类教程:文本与中文处理

公开接口

函数参数
sp_pads, width, pad=" ", side="right"
sp_pad_lefts, width, pad=" "
sp_pad_rights, width, pad=" "
sp_pad_boths, width, pad=" "
sp_repeats, n
sp_truncates, width, suffix="..."
sp_limits, width
sp_zeropadn, width

包内说明(源码头注释)

text
strpad.px — 字符串填充与重复(PHP str_pad / str_repeat / str_truncate)
依赖: 无

函数列表:
sp_pad(s, width, pad=" ", side="right")  → string  # 填充到指定宽度
sp_pad_left(s, width, pad=" ")            → string
sp_pad_right(s, width, pad=" ")           → string
sp_pad_both(s, width, pad=" ")            → string
sp_repeat(s, n)                           → string  # 重复 n 次
sp_truncate(s, width, suffix="...")       → string  # 截断到宽度+后缀
sp_limit(s, width)                        → string  # 硬截断
sp_zeropad(n, width)                      → string  # 数字零填充