字符串操纵,升级! – 由Chris Kankiewicz(@phlak.dev)
介绍
Twine是带有表现力的流利语法的字符串操纵库。
要求
- php> = 8.1
- 多键字符串扩展
- OpenSSL扩展
与作曲家安装
composer require phlak/ Twine
入门
首先,导入Twine :
use PHLAK \\ Twine ;
然后,通过新的Twine Twine \\Str对象并将字符串作为第一个参数来实例化对象。
$ string = new Twine \\ Str ( \' john pinkerton \' );
您也可以通过make()方法在统计上实例化Twine \\Str对象。
$ string = Twine \\Str:: make ( \' john pinkerton \' );
或使用全局str()辅助方法。该方法将字符串作为唯一的参数,并返回一个Twine \\Str对象。
$ string = str ( \' john pinkerton \' );
有一个具体的Twine \\Str实例后,您可以像其他任何字符串一样对待它。这包括对其进行回声或使用PHP的任何内置字符串函数。
echo $ string ; // Echos \'john pinkerton\' str_shuffle ( $ string ) // Returns something like \'enoipo ktnjhnr\' strlen ( $ string ); // Returns 14
但是, Twine的强度来自其内置方法。
$ string -> echo (); // Echos \'john pinkerton\' $ string -> shuffle (); // Returns something like \'enoipo ktnjhnr\' $ string -> length (); // Returns 14 // or some more interesting methods $ string -> reverse (); // Returns \'notreknip nhoj\' $ string -> contains ( \' pink \' ); // Returns true $ string -> replace ( \' pink \' , \' purple \' ); // Returns \'john purpleton\' $ string -> snakeCase (); // Returns \'john_pinkerton\'
此时,您可以通过调用其许多内置方法中的任何一种开始使用Twine 。
可用方法
after • append • base64 • base64Decode • base64Encode • bcrypt • before • camelCase • characters • chunk • contains • count • crc32 • crypt • decrypt • echo • encoding • encrypt • endsWith • equals • explode • first • format • from • hex • hexEncode • hexDecode • insensitiveMatch • insert • in • isAlphabetic • isAlphanumeric • isEmpty • isLowercase • isNotEmpty • isNumeric • isPrintable • isPunctuation • isUppercase • isWhitespace • join • kebabCase • last • length • lowercase • lowercaseFirst • lowercaseWords • match • matchAll • matches • md5 • nth • pad • padBoth • padLeft • padRight • pascalCase • prepend • repeat • replace • reverse • SHA1•SHA256•洗牌•相似性•Snakecase•分裂•startswith•striplycase•studlycase•substring•to•Trim•Trimleft•Trimleft•Trimright•trimright•truncate•uppercase•uppercasefirst•uppercasefirst•uppercase•uppercase•url•url•wress•wrapard•wrapsoft•wrapsoft•wrapsoft•wrapsoft•wrapsoft•wrapsoft
方法链
Twine方法可以流利地操纵麻线。这里有一些示例链:
进行底条比较:
Twine\\Str(\’john pinkerton\’);
$string->substring(5, 4)->equals(\’pink\’); // Returns true\”>
$ string = new Twine \\ Str ( \' john pinkerton \' ); $ string -> substring ( 5 , 4 )-> equals ( \' pink \' ); // Returns true
根据RFC 2045编码文件。
Twine\\Str(file_get_contents(\’garbage.bin\’));
$string->base64()->wrap(76, \”\\r\\n\”, Twine \\Config\\Wrap::HARD);\”>
$ string = new Twine \\ Str ( file_get_contents ( \' garbage.bin \' )); $ string -> base64 ()-> wrap ( 76 , \"\\r\\n\" , Twine \\ Config \\Wrap:: HARD );
完整文档中可用的其他详细信息,网址为https://twine.ph**l*ak.net。
多晶弦
通过依靠PHP的多键字符串扩展(MBSTRING)来执行字符串操作, Twine目标是多级字符串兼容性。因此,需要MBSTRING扩展名。多型字符串包括UTF-8和UCS-2等UNICODE编码。
ChangElog
更改列表可以在GitHub版本页面上找到。
故障排除
为了一般的帮助和支持,加入我们的GitHub讨论或与Bluesky接触。
请向GitHub问题跟踪器报告错误。
版权
该项目已根据MIT许可获得许可。
