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

textfmt 包

文本格式化工具

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

安装与引入

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

公开接口

函数参数
tf_nl2brs
tf_nl2br_xhtmls
tf_chunk_splits, chunklen = 76, end = "\r\n"
tf_strtrs, from_str, to_str
tf_strtr_tables, table
tf_qp_encodes
tf_qp_decodes
tf_wordwraps, width = 75, br = "\n", cut = false
tf_strip_tagss
tf_addslashess
tf_stripslashess
其余 2 个 def(内部与辅助,可直接调用但不属稳定接口)
函数参数
tf_hex_byteb
tf_hex_to_inth

包内说明(源码头注释)

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(别名)
============================================================