PHP中面向对象的字符串/数字? [英] Object orientated strings / numbers in PHP?

查看:111
本文介绍了PHP中面向对象的字符串/数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在看Ruby,它具有非常好的OO结构,不像PHP那样具有类似C的字符串函数.我想知道是否有一个扩展程序可以将字符串变成对象,以便您可以像这样使用它们:

I was looking at Ruby and it has a very nice OO structure unlike PHP with C-like string functions. I was wondering if there is an extension which makes strings into objects so you could use them like this:

$str = "sometext";
echo "len:" . $str->length; //would print 'len: 8'

推荐答案

看看这个...

> 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内部函数或自定义函数来操纵字符串.

The class supports the extensions mbstring and iconv, and the package PHP-UTF8. It chooses the best available function for each method In addition, it provides many new methods. Some of them are: substringBetween, splice, startWith, endsWith and squeeze. It is also possible to use PHP internal functions, or custom functions, to manipulate the string.

示例代码:

<?php

include('string.php');

$str = new String('sometext');
echo $str->length; //prints 8
echo $str->getLength(); //prints 8

?>

我以前从未使用过此类,但是通过查看其文档,它具有一些非常有趣的方法.大写,charAt,compareTo,contains等.

I have never used this class before but by looking at its documentation it has some pretty interesting methods. capitalize, charAt, compareTo, contains, etc..

这篇关于PHP中面向对象的字符串/数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆