juanchosl/datamanipulation
Composer 安装命令:
composer require juanchosl/datamanipulation
包简介
Little methods collection in order to manipulate variables contents
README 文档
README
Description
Little methods collection in order to manipulate variables contents. Group of some features in order to clean, modify, convert, apply math operations and some other actions
Install
composer require juanchosl/datamanipulation
Manipulators
Strings
Perform actions over strings, using multibyte functions where are available, and returns a new StringManipulator object in order to mantain inmutability over previous entities
| Manipulation | MultiByte | Description |
|---|---|---|
| substring | X | Extract a part of a string, starting from indicated offset and with the desired lenght |
| substringBeforeChar | X | Extract a part of a string, ending at indicated char |
| substringAfterChar | X | Extract a part of a string, starting from indicated char |
| repeat | Repeat the string n times | |
| format | Apply format, with indicated values, to the string | |
| replace | Search and replace a substring, can be case sensitive or not | |
| reverse | Apply a reverse to the string | |
| toUpperFirst | X | To upper the first char of the string |
| toLowerFirst | X | To lower the first char of the string |
| toUpperWords | To upper the first char of every word into the string, can be indicated the char separator, not only spaces | |
| toUpper | X | To upper all the string |
| toLower | X | To lower all the string |
| padding | X | Fill the string to the desired lenght with the value, at the left, rigth or both |
| preppend | X | Concat a new value at the start of the string, can be indicated an union char, a space is used if not |
| concatenation | X | Concat a new value at the end of the string, can be indicated an union char, a space is used if not |
| chunk | X | Convert to a multiline string with a fix lenght |
| wordWrap | Convert to a multiline string with a fix lenght, but safely for word, ensuring do not cut, applying from the previous space | |
| trim | X | Clean a string, removing spaces or control chars at the start or the end of the string |
| ltrim | X | Clean a string, removing spaces or control chars at the start of the string |
| rtrim | X | Clean a string, removing spaces or control chars at the end of the string |
| eol | X | Convert breaklines chars (\r,\n,\r\n) to the desired new char, in order to ensure the use of PHP_EOL constant for unknow origins |
| shuffle | Apply a random shuffle | |
| explode | Explode a string and returns a StringManipulators collection for every parts | |
| rotate13 | Apply a rot13 transformation | |
| md5 | Calculate the md5 | |
| quotedPrintableEncode | Convert form 8bits string to QP string, following the rules from RFC2045 | |
| quotedPrintableDecode | Convert to 8bits string from QP string, following the rules from RFC2045 | |
| uuEncode | Encode the string using the uuencode algorithm | |
| uuDecode | Decode a uuencoded string | |
| urlEncode | Encode the string using the rawurlencode algorithm, following the rules from RFC3986 | |
| urlDecode | Decode a rawurlencoded string, following the rules from RFC3986 | |
| base64Encode | Encode to Base 64 | |
| base64Decode | Decode from Base 64 | |
| base64UrlEncode | Encode to Base 64 URL safe | |
| base64UrlDecode | Decode from Base 64 URL safe | |
| binToHex | Convert the binary string to hexadecimal equivalent | |
| hexToBin | Convert the hexadecimal string to binary data | |
| hashHmac | Calculate the hash, using an algorithm and key, of a string |
Numbers
| Operation | Description |
|---|---|
| absolute | The positive value, ignoring the original, allways to positive |
| negation | the inversed, if is a positive, converts to negative |
| sum | sum a quantity to the internal object value |
| sub | substraction a quantity to the internal object value |
| product | calculate the product with the internal object value |
| division | calculate the division with the internal object value |
| module | calculate the module of a division with the internal object value |
| exponent | calculate the exponent of the internal object value to the indicated exponent |
| root | calculate the root of the internal object value to the indicated degree, square by default |
| percent | calculate the indicated percentage of the internal object value |
| increasePercent | add the indicated percentage of the internal object value |
| decreasePercent | down the indicated percentage of the internal object value |
| roundHalfUp | |
| roundHalfDown | |
| roundAwayToZero | |
| roundAwayFromZero | |
| roundToHighInteger | |
| roundToLowInteger | |
| min | pass an array or floats list and return the min including the internal value into the comparation |
| max | pass an array or floats list and return the max including the internal value into the comparation |
echo (string)(NumbersManipulators($pvu = 100)) ->product($units = 10) ->increasePercent($taxes = 21); //1210
Date + Times
Check, parse a value as a date from some origins and formats, and retunrs a DateTime instance
Create from excel time value
echo (new DateManipulators()) ->fromExcel(46023) ->format("Y-m-d"); // 2026-01-01
Create from timestamp
echo (new DateManipulators()) ->fromTimestamp(1735689600) ->format("Y-m-d"); // 2026-01-01
Create from string
echo (new DateManipulators()) ->fromString("Thursday, 01-Jan-26 00:00:00 UTC") ->format("Y-m-d"); // 2026-01-01
Create from knowed format
echo (new DateManipulators()) ->fromFormatString(20260101, "Ymd") ->format("Y-m-d"); // 2026-01-01
Sanitizers
Filter, clean and convert contents variables, for use from forms, file contents, DTOs or other origins
- Strings
- Numbers
Strings
Clean Email
$sanitizer = (new StringSanitizers())->email(); echo $sanitizer('Juan. Sanchez@tecnicosweb.com'); //Juan.Sanchez@tecnicosweb.com
Clean URL
Add Slashes
$sanitizer = (new StringSanitizers())->addSlashes(); echo $sanitizer('SELECT * FROM "table"'); //SELECT * FROM \"table\"
HTML Special Chars
FILTER_SANITIZE_FULL_SPECIAL_CHARS.
$sanitizer = (new StringSanitizers())->htmlSpecialChars(); echo $sanitizer('<div>Text</div>'); //<div>Text</div>
Strip HTML Tags
$sanitizer = (new StringSanitizers())->stripTags(); echo $sanitizer('<div>Text</div>'); //Text
Combine Sanitizators
$sanitizator= (new StringSanitizers())->stripTags()->htmlSpecialChars(); echo $sanitizator("<div>Camión&\r\n</div>"); //"Camión&\r\n"
Extended String Sanitizators
setStripBacktick
Remove or not the backtick character, an executor for unix terminals, in order to avoid code execution
setStripChars
You can indicate if would remove the control ASCII chars (less than 32) or the extended ASCII codes (greather than 127)
setEncodeChars
You can indicate if would encode the control ASCII chars (less than 32) or the extended ASCII codes (greather than 127)
unsafe
FILTER_UNSAFE_RAW.+ FILTER_FLAG_EMPTY_STRING_NULL
safe
FILTER_SANITIZE_SPECIAL_CHARS. + FILTER_FLAG_EMPTY_STRING_NULL
urlEncode
FILTER_SANITIZE_ENCODED. + FILTER_FLAG_EMPTY_STRING_NULL
hmtlEncode
FILTER_SANITIZE_SPECIAL_CHARS. + FILTER_FLAG_EMPTY_STRING_NULL + FILTER_FLAG_ENCODE_AMP
$sanitizator= (new StringSanitizers())->stripTags()->htmlSpecialChars(); echo $sanitizator("<div>Camión&\r\n</div>"); //"Camión&\r\n"
Numbers
Can extract and parse from an origin, the numeric part, extracting the integer or float contained, removing (or not) the thousand separators. Into code, the colon is a parameters separator, for this reason, by default, we don't preserve it, but you can preserve thousand separator pasing TRUE.
Floats
FILTER_SANITIZE_NUMBER_FLOAT. + FILTER_FLAG_ALLOW_THOUSAND
$sanitizer = (new NumberSanitizers())->float($with_thousand_separator = false); echo $sanitizer('2,000.22€'); //2000.22
Integers
FILTER_SANITIZE_NUMBER_INT. + FILTER_FLAG_ALLOW_THOUSAND
$sanitizer = (new NumberSanitizers())->integer($with_thousand_separator = false); echo $sanitizer('Z123456789N'); //123456789
For integer sanitization, the FILTER_FLAG_ALLOW_FRACTION is not used, allways perform a number_format with 0 fraction for remove the decimals, taken only the integer part, not just removing dot
$sanitizer = (new NumberSanitizers())->integer($with_thousand_separator = false); echo $sanitizer('2,000.22€'); //2000
juanchosl/datamanipulation 适用场景与选型建议
juanchosl/datamanipulation 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 112 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 12 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「numbers」 「arrays」 「strings」 「manipulation」 「variables」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 juanchosl/datamanipulation 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 juanchosl/datamanipulation 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 juanchosl/datamanipulation 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The slick/configuration component provides an easy-to-use solution for managing configuration files in your PHP applications.
Generate pseudo locale string for unicode testing and marking missing strings
Partition problem for balanced arrays splitting made easy.
Rutils Symfony 2 bundle
Strings Component provide a fluent, object-oriented interface for working with multibyte string, allowing you to chain multiple string operations together using a more readable syntax compared to traditional PHP strings functions.
Arrays Component provide a fluent, object-oriented interface for working with arrays, allowing you to chain multiple arrays operations together using a more readable syntax compared to traditional PHP arrays functions.
统计信息
- 总下载量: 112
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 23
- 依赖项目数: 5
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-11