普贤教程 › 包参考
textfmt 包
文本格式化工具
| 项 | 值 |
|---|---|
| 包名 | textfmt |
| 版本 | 0.1.0 |
| 入口 | textfmt.px |
| 分类 | 文本与中文处理 |
| 文件数 / 行数 | 1 / 324 |
安装与引入
bash
pxpkg init # 首次 pxpkg add textfmt@0.1.0 pxpkg install
px
import textfmt所属分类教程:文本与中文处理
公开接口
| 函数 | 参数 |
|---|---|
tf_nl2br | s |
tf_nl2br_xhtml | s |
tf_chunk_split | s, chunklen = 76, end = "\r\n" |
tf_strtr | s, from_str, to_str |
tf_strtr_table | s, table |
tf_qp_encode | s |
tf_qp_decode | s |
tf_wordwrap | s, width = 75, br = "\n", cut = false |
tf_strip_tags | s |
tf_addslashes | s |
tf_stripslashes | s |
其余 2 个 def(内部与辅助,可直接调用但不属稳定接口)
| 函数 | 参数 |
|---|---|
tf_hex_byte | b |
tf_hex_to_int | h |
包内说明(源码头注释)
text
============================================================ 普贤生态库:registry/textfmt — 文本格式化工具 ------------------------------------------------------------ 纯函数库,双模式一致。 对齐 PHP nl2br / chunk_split / strtr / quoted_printable_encode/decode / wordwrap: tf_nl2br(s) → \n → <br>\n tf_nl2br_xhtml(s) → \n → <br /> tf_chunk_split(s, chunklen, end) → 按固定宽度分块+分隔符 tf_strtr(s, from, to) → 字符/串映射表批量替换 tf_strtr_table(s, table) → dict 映射表替换 tf_qp_encode(s) → Quoted-Printable 编码 tf_qp_decode(s) → Quoted-Printable 解码 tf_wordwrap(s, width, break, cut) → 按宽度换行(PHP wordwrap 语义) tf_strip_tags(s) → 去除 HTML 标签 tf_addslashes(s) → PHP addslashes(' " \ NUL 前加 \) tf_stripslashes(s) → PHP stripslashes(去除 \ 转义) tf_quoted_printable_encode = tf_qp_encode(别名) ============================================================