我在看Ruby,它有一个非常好的OO结构,不像PHP那样具有类似C的字符串函数.我想知道是否有一个扩展使字符串成为对象,所以你可以像这样使用它们:
$str = "sometext";
echo "len:" . $str->length; //would print 'len: 8'
Run Code Online (Sandbox Code Playgroud)
看看这个...
http://code.google.com/p/php-string/downloads/detail?name=string.php&can=2&q=
该类支持扩展名mbstring和iconv,以及包PHP-UTF8.它为每种方法选择最佳可用功能.此外,它还提供了许多新方法.其中一些是:substringBetween,splice,startWith,endsWith和squeeze.也可以使用PHP内部函数或自定义函数来操作字符串.
示例代码:
<?php
include('string.php');
$str = new String('sometext');
echo $str->length; //prints 8
echo $str->getLength(); //prints 8
?>
Run Code Online (Sandbox Code Playgroud)
我以前从未使用过这个类,但通过查看它的文档,它有一些非常有趣的方法.大写,charAt,compareTo,包含等等.