lacus/cpf-fmt
Composer 安装命令:
composer require lacus/cpf-fmt
包简介
Utility function to format CPF (Brazilian personal ID)
README 文档
README
Utility function/class to format CPF (Brazilian ID document).
| Passing ✔ | Passing ✔ | Passing ✔ | Passing ✔ |
Installation
# using Composer
$ composer require lacus/cpf-fmt
Import
<?php // Using class-based resource use Lacus\CpfFmt\CpfFormatter; // Or using function-based one use function Lacus\CpfFmt\cpf_fmt;
Usage
Object-Oriented Usage
$formatter = new CpfFormatter(); $cpf = '47844241055'; echo $formatter->format($cpf); // returns '478.442.410-55' // With options echo $formatter->format( $cpf, hidden: true, hiddenKey: '#', hiddenStart: 3, hiddenEnd: 10 ); // returns '478.###.###-##'
The options can be provided to the constructor or the format() method. If passed to the constructor, the options will be attached to the CpfFormatter instance. When passed to the format() method, it only applies the options to that specific call.
$cpf = '12345678910'; $formatter = new CpfFormatter(hidden: true); echo $formatter->format($cpf); // '123.***.***-**' echo $formatter->format($cpf, hidden: false); // '123.456.789-10' merges the options to the instance's echo $formatter->format($cpf); // '123.***.***-**' uses only the instance options
Imperative programming
The helper function cpf_fmt() is just a functional abstraction. Internally it creates an instance of CpfFormatter and calls the format() method right away.
$cpf = '47844241055'; echo cpf_fmt($cpf); // returns '478.442.410-55' echo cpf_fmt($cpf, hidden: true); // returns '478.***.***-**' echo cpf_fmt($cpf, dotKey: '', dashKey: '_'); // returns '478442410_55'
Formatting Options
| Parameter | Type | Default | Description |
|---|---|---|---|
escape |
?bool |
false |
Whether to HTML escape the result |
hidden |
?bool |
false |
Whether to hide digits with a mask |
hiddenKey |
?string |
'*' |
Character to replace hidden digits |
hiddenStart |
?int |
3 |
Starting index for hidden range (0-10) |
hiddenEnd |
?int |
10 |
Ending index for hidden range (0-10) |
dotKey |
?string |
'.' |
String to replace dot characters |
dashKey |
?string |
'-' |
String to replace dash character |
onFail |
?callable |
fn($v) => $v |
Fallback function for invalid input |
Contribution & Support
We welcome contributions! Please see our Contributing Guidelines for details. But if you find this project helpful, please consider:
- ⭐ Starring the repository
- 🤝 Contributing to the codebase
- 💡 Suggesting new features
- 🐛 Reporting bugs
License
This project is licensed under the MIT License - see the LICENSE file for details.
Changelog
See CHANGELOG for a list of changes and version history.
Made with ❤️ by Lacus Solutions
lacus/cpf-fmt 适用场景与选型建议
lacus/cpf-fmt 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 412 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 09 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「format」 「formatting」 「mask」 「cpf」 「br」 「pt-BR」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 lacus/cpf-fmt 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lacus/cpf-fmt 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 lacus/cpf-fmt 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Provides a simple decimal/roman number converter
A library that can render international postal addresses in different formats.
Softonic OpenApi validation formats extension
Never configure mask permissions for editors manually ever again!
ke_search Indexer for all Mask-Elements
Tools to convert between .NET and PHP date formats
统计信息
- 总下载量: 412
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 27
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-03