klaussilveira/simplestring

此包的最新版本(v1.0.0)没有可用的许可信息。

SimpleString 类。

v1.0.0 2013-10-04 17:03 UTC

This package is auto-updated.

Last update: 2024-09-10 20:04:39 UTC


README

Build Status

A small library for string manipulation with PHP. SimpleString uses method overloading to create an object-oriented interface for the built-in string functions in PHP. It implements a fluent interface, improving how we manipulate strings, and extends functionality by providing common implementations. It also aims to eliminate the problems of unorganized function names.

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.

作者和贡献者

许可证

New BSD 许可证

待办事项

  • 添加更多功能,但保持库简单易用(忠于其名称)
  • 创建更好的文档(详细说明每个方法)
  • 错误处理可以,并且应该得到改进(抛出合理的异常)
  • 完成 Multibyte String 意识

使用 SimpleString

The idea behind SimpleString is to keep things very easy to use, while giving lot's of power to the user. Check it out

<?php 

// Example
$string = new SimpleString('Lorem ipsum dolor sit amet lorem ipsum');
$string->shorten(10);
$string->toSentenceCase();
echo $string;

// Fluent interface example
$string = new SimpleString('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 SimpleString('Lorem ipsum dolor sit amet lorem ipsum');
$string->tolower()->replace('lorem', 'mortem');
echo $string;