klaussilveira / simple-string
该软件包已被废弃且不再维护。未建议替代软件包。
一个用于 PHP 面向对象字符串操作的库。
1.0.0
2014-03-29 01:51 UTC
Requires
- php: >=5.3.3
This package is not auto-updated.
Last update: 2024-03-25 19:36:28 UTC
README
一个用于 PHP 字符串操作的库。SimpleString 使用方法重载来为 PHP 内置的字符串函数创建面向对象的接口。它实现了流畅接口,提高了我们操作字符串的方式,并通过提供常见的实现扩展了功能。它还旨在消除无组织函数名称的问题。
SimpleString 还使用重载来为内置字符串函数创建面向对象的接口。以 str 或 str_ 开头的函数可以直接使用其实际名称,而不需要前缀。所以:strtolower = tolower,str_replace = replace。返回值不是字符串的函数是无效的,并将抛出异常。
作者和贡献者
- Klaus Silveira(创建者、开发者、支持者)
- Thiago Lechuga(开发者)
- Guto Maia(开发者)
许可证
待办事项
- 添加更多功能,但保持库简单易用(忠实于其名称)
- 创建更好的文档(详细说明每个方法)
- 错误处理可以,而且应该得到改进(抛出合理的异常)
- 完成对 Multibyte String 的支持
使用 SimpleString
SimpleString 的理念是保持操作非常简单,同时为用户提供大量功能。看看它吧
<?php use Simple\Type\String; // Example $string = new String('Lorem ipsum dolor sit amet lorem ipsum'); $string->shorten(10); $string->toSentenceCase(); echo $string; // Fluent interface example $string = new String('Lorem ipsum dolor sit amet lorem ipsum'); $string->shorten(15)->toCamelCase(); echo $string; /** * SimpleString also uses overloading to create an object-oriented * interface for built-in string functions. Functions starting with * str or str_ can just be used with their actual name, not prefix. * * So: strtolower = tolower, str_replace = replace. * * Functions whose return values are not string are invalid and will * throw exceptions. */ $string = new String('Lorem ipsum dolor sit amet lorem ipsum'); $string->tolower()->replace('lorem', 'mortem'); echo $string;