![Stringy](http://danielstjules.com/github/stringy-logo.png)
A PHP string manipulation library with multibyte support. Offers both OO method
chaining and a procedural-style static wrapper. Tested and compatible with
PHP 5.3+ and HHVM. Inspired by underscore.string.js.
[![Build Status](https://api.travis-ci.org/danielstjules/Stringy.svg?branch=master)](https://travis-ci.org/danielstjules/Stringy)
* [Requiring/Loading](#requiringloading)
* [OO and Procedural](#oo-and-procedural)
* [Implemented Interfaces](#implemented-interfaces)
* [PHP 5.6 Creation](#php-56-creation)
* [Methods](#methods)
* [at](#at)
* [camelize](#camelize)
* [chars](#chars)
* [collapseWhitespace](#collapsewhitespace)
* [contains](#contains)
* [containsAll](#containsall)
* [containsAny](#containsany)
* [countSubstr](#countsubstr)
* [create](#create)
* [dasherize](#dasherize)
* [delimit](#delimit)
* [endsWith](#endswith)
* [ensureLeft](#ensureleft)
* [ensureRight](#ensureright)
* [first](#first)
* [getEncoding](#getencoding)
* [hasLowerCase](#haslowercase)
* [hasUpperCase](#hasuppercase)
* [htmlDecode](#htmldecode)
* [htmlEncode](#htmlencode)
* [humanize](#humanize)
* [indexOf](#indexof)
* [indexOfLast](#indexoflast)
* [insert](#insert)
* [isAlpha](#isalpha)
* [isAlphanumeric](#isalphanumeric)
* [isBlank](#isblank)
* [isHexadecimal](#ishexadecimal)
* [isJson](#isjson)
* [isLowerCase](#islowercase)
* [isSerialized](#isserialized)
* [isUpperCase](#isuppercase)
* [last](#last)
* [length](#length)
* [longestCommonPrefix](#longestcommonprefix)
* [longestCommonSuffix](#longestcommonsuffix)
* [longestCommonSubstring](#longestcommonsubstring)
* [lowerCaseFirst](#lowercasefirst)
* [pad](#pad)
* [padBoth](#padboth)
* [padLeft](#padleft)
* [padRight](#padright)
* [regexReplace](#regexreplace)
* [removeLeft](#removeleft)
* [removeRight](#removeright)
* [replace](#replace)
* [reverse](#reverse)
* [safeTruncate](#safetruncate)
* [shuffle](#shuffle)
* [slugify](#slugify)
* [startsWith](#startswith)
* [substr](#substr)
* [surround](#surround)
* [swapCase](#swapcase)
* [tidy](#tidy)
* [titleize](#titleize)
* [toAscii](#toascii)
* [toLowerCase](#tolowercase)
* [toSpaces](#tospaces)
* [toTabs](#totabs)
* [toTitleCase](#totitlecase)
* [toUpperCase](#touppercase)
* [trim](#trim)
* [trimLeft](#trimLeft)
* [trimRight](#trimRight)
* [truncate](#truncate)
* [underscored](#underscored)
* [upperCamelize](#uppercamelize)
* [upperCaseFirst](#uppercasefirst)
* [Links](#links)
* [Tests](#tests)
* [License](#license)
## Requiring/Loading
If you're using Composer to manage dependencies, you can include the following
in your composer.json file:
```json
{
"require": {
"danielstjules/stringy": "~1.10"
}
}
```
Then, after running `composer update` or `php composer.phar update`, you can
load the class using Composer's autoloading:
```php
require 'vendor/autoload.php';
```
Otherwise, you can simply require the file directly:
```php
require_once 'path/to/Stringy/src/Stringy.php';
// or
require_once 'path/to/Stringy/src/StaticStringy.php';
```
And in either case, I'd suggest using an alias.
```php
use Stringy\Stringy as S;
// or
use Stringy\StaticStringy as S;
```
## OO and Procedural
The library offers both OO method chaining with `Stringy\Stringy`, as well as
procedural-style static method calls with `Stringy\StaticStringy`. An example
of the former is the following:
```php
use Stringy\Stringy as S;
echo S::create('Fòô Bàř', 'UTF-8')->collapseWhitespace()->swapCase(); // 'fÒÔ bÀŘ'
```
`Stringy\Stringy` has a __toString() method, which returns the current string
when the object is used in a string context, ie:
`(string) S::create('foo') // 'foo'`
Using the static wrapper, an alternative is the following:
```php
use Stringy\StaticStringy as S;
$string = S::collapseWhitespace('Fòô Bàř', 'UTF-8');
echo S::swapCase($string, 'UTF-8'); // 'fÒÔ bÀŘ'
```
## Implemented Interfaces
`Stringy\Stringy` implements the `IteratorAggregate` interface, meaning that
`foreach` can be used with an instance of the class:
``` php
$stringy = S::create('Fòô Bàř', 'UTF-8');
foreach ($stringy as $char) {
echo $char;
}
// 'Fòô Bàř'
```
It implements the `Countable` interface, enabling the use of `count()` to
retrieve the number of characters in the string:
``` php
$stringy = S::create('Fòô', 'UTF-8');
count($stringy); // 3
```
Furthermore, the `ArrayAccess` interface has been implemented. As a result,
`isset()` can be used to check if a character at a specific index exists. And
since `Stringy\Stringy` is immutable, any call to `offsetSet` or `offsetUnset`
will throw an exception. `offsetGet` has been implemented, however, and accepts
both positive and negative indexes. Invalid indexes result in an
`OutOfBoundsException`.
``` php
$stringy = S::create('Bàř', 'UTF-8');
echo $stringy[2]; // 'ř'
echo $stringy[-2]; // 'à'
isset($stringy[-4]); // false
$stringy[3]; // OutOfBoundsException
$stringy[2] = 'a'; // Exception
```
## PHP 5.6 Creation
As of PHP 5.6, [`use function`](https://wiki.php.net/rfc/use_function) is
available for importing functions. Stringy exposes a namespaced function,
`Stringy\create`, which emits the same behaviour as `Stringy\Stringy::create()`.
If running PHP 5.6, or another runtime that supports the `use function` syntax,
you can take advantage of an even simpler API as seen below:
``` php
use function Stringy\create as s;
// Instead of: S::create('Fòô Bàř', 'UTF-8')
s('Fòô Bàř', 'UTF-8')->collapseWhitespace()->swapCase();
```
## Methods
In the list below, any static method other than S::create refers to a method in
`Stringy\StaticStringy`. For all others, they're found in `Stringy\Stringy`.
Furthermore, all methods that return a Stringy object or string do not modify
the original. Stringy objects are immutable.
*Note: If `$encoding` is not given, it defaults to `mb_internal_encoding()`.*
#### at
$stringy->at(int $index)
S::at(int $index [, string $encoding ])
Returns the character at $index, with indexes starting at 0.
```php
S::create('fòô bàř', 'UTF-8')->at(6);
S::at('fòô bàř', 6, 'UTF-8'); // 'ř'
```
#### camelize
$stringy->camelize();
S::camelize(string $str [, string $encoding ])
Returns a camelCase version of the string. Trims surrounding spaces,
capitalizes letters following digits, spaces, dashes and underscores,
and removes spaces, dashes, as well as underscores.
```php
S::create('Camel-Case')->camelize();
S::camelize('Camel-Case'); // 'camelCase'
```
#### chars
$stringy->chars();
S::chars(string $str [, string $encoding ])
Returns an array consisting of the characters in the string.
```php
S::create('Fòô Bàř', 'UTF-8')->chars();
S::chars('Fòô Bàř', 'UTF-8'); // array(F', 'ò', 'ô', ' ', 'B', 'à', 'ř')
```
#### collapseWhitespace
$stringy->collapseWhitespace()
S::collapseWhitespace(string $str [, string $encoding ])
Trims the string and replaces consecutive whitespace characters with a
single space. This includes tabs and newline characters, as well as
multibyte whitespace such as the thin space and ideographic space.
```php
S::create(' Ο συγγραφέας ')->collapseWhitespace();
S::collapseWhitespace(' Ο συγγραφέας '); // 'Ο συγγραφέας'
```
#### contains
$stringy->contains(string $needle [, boolean $caseSensitive = true ])
S::contains(string $haystack, string $needle [, boolean $caseSensitive = true [, string $encoding ]])
Returns true if the string contains $needle, false otherwise. By default,
the comparison is case-sensitive, but can be made insensitive
by setting $caseSensitive to false.
```php
S::create('Ο συγγραφέας �
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
PHP实例开发源码-Antted PHP版帮助中心系统源码.zip (2000个子文件)
0040d7de8d35c6fc418e8e518ff7efb3d82ccd 203B
01db16301859a832e01912fd7e2e3620bd1e1c 61B
037dedd433d03f8fe9c213bd805bc17a77d456 1KB
04740fde9c7e1192c3f2bace0613a87900a633 185B
04fa54a145525ca8cfa36dbf6eba3882505745 287B
06b89a48f30720dd6920446e548879af5c7db7 288B
0843178f864397d1e783bda4730e7657353e1e 103B
08cd2f62c9d82c7692efca976dacd68421b3d0 598B
09b39b3506bf610980f2dca90a9a5c8ec00a52 156B
0a0f87f407b4239dcadd254735da271856476c 805B
0a92a6671daf6fbaea724cb705c7e1a9928ccf 144B
0acfb0157960850104e121c9f8963c49b18322 5KB
0b159c493dae3b2f9ec79d3f6a605440e8c8f2 87B
0b1f25da47a61e6e879c9592a083150cbb10ea 4KB
0c50424c22843e6798dd76181d8aa5e6364c72 189B
0c51032696907507eb4230e9cb7576d601645f 217B
0c85076c495f6ef59b9b752b4186c4b943ec51 53B
0c9867c86a48fccf70fa9d796e956efb7e35e0 3KB
0c9c9c8b09f1077fcb55a02f61fe3edfb103af 235B
0cf9e3e7e5796d2919904e025a53355bf7b3ed 3KB
0e54f6f47e1e8ec406bf8c963398b7fc4dfeee 237B
0e811dcd3a950f74d3ddd7de87c1ba9922cd08 86B
0e8e57fb1b89f4e41aab86d105bf8c21f6307b 6KB
0eac28678087ab2a37944bc4d6ae9790274945 2KB
0efb54dde3d7a831e433ae22cf1ba52b9d7729 628B
10b0ae427fb83c31d5553deefd2ffe16195114 59B
110b3b265abd3ab569a1df764a950119e1b211 143B
119f85acfc08699ab2d3f23c89740f84b6785c 375B
120953d54c19b02e35ebf6745856273bf6d8f7 288B
1223cb69ef8a49bae3bfabf741cb70aecac741 483B
1380bd151a989399e1b59682b7245cc3d5b63c 285B
138c48fcd8e5eed131bc3ab1be0ff28a06e2eb 2KB
1472841b3bc669907ae341b2eeb27ad76313fa 48B
1477078c445ba75c8a2e11bec35356b955e7c8 124B
14c5b050bdfa9e5c691661d721eb04bc5779bb 615B
14d11b3f1fb6d8e65f4e264fb89b103791849f 379B
152bd0fe7e0f065df0cdfb0f647f713ed34f7f 5KB
154430adc3539ff56182d2ac1101eb2b032d52 1KB
15931f3ed86957e3a13e02bf610bea347176db 53B
1621af8d789463e972867aa49039f4795b89a3 255B
166b81e00f5b4c3b9c25b8369565ba213e456c 194B
16a81227e17757c13f4db6f94dde9d72f6941a 5KB
16b48c03f6aabd8a130a2345f89e4b110ba146 310B
16e250efff15d5b8fd18ab53d36e1c6fcb8059 46B
17796e2429a29dfd3c0d223afbccf81a1db403 202B
180b40e14260f3b046e354dce7f50936965b09 313B
183122f4676de1b33a0e15d253772b298c2d3b 146B
185684e7d6067d635eeaddb987c0935606c81c 568B
186194ff9e6465330118ad1ca4f04256dd04f2 684B
188f36fc1567c3599956be0677e7bad9ef941a 114B
19e2d25da2ed418ab34a413cb85376f66d4ebf 144B
19f77ab97980e6fe3528153af8a90aef6dacf8 5KB
1a3a9a001ecef255184374b63ef18f1c2b27bb 152B
1a470c1ef16e08421e594f814462954abf0280 221B
1aa4b60927b1660744e191612f9078c15d74b7 186B
1aa80e7eb61c35889db07e3cdf228dff7577d0 459B
1d3620cce782aa50564c733f1e5cc0df20938f 425B
1ee3efd2ce690203d250cc4513b478894c5cc8 157B
1f6918775a19be0e17ed56c8a86b3841326d79 306B
1fd2e09d5eaa765d5668d130174382eae5f7e1 404B
20511f52a6b0169600c037a6f54129fcc31853 287B
206ca6e15d22664d5054a06b9a3620a9808563 87B
209c6e8fb5e02b8ddbe90a5198902ba2407464 591B
20f6dae510b408f28602c73785730d4e1a3780 99B
21699110e5629e7debead1de438af23acdf6f0 353B
21eb4145147c611e3a58261eb593c9aa7172da 176B
2209140d9ced41701e3c411241f123a53502a8 147B
222418068b1592bf0794d137ef4e28093b884c 272B
224062c7c071526eda458dd34ae587393d76dd 118B
226514bf1c7d0a511d809a708c7acd3a3b0223 125B
22e1760a8c2ce3303abb76f309f7330021efd4 207B
22eae8ffb5a2a92d66d5ca8f564e0d9497c6ad 188B
23f0b4a5cdb3e89ce78c07dc059550715f9fdd 146B
24bb2ec6669490863d988941b1701469f5575e 1KB
259480ca1de4007dcdabf5cc5cc9ab4659ec02 1016B
25ebb88f56d30cd98ef3a37521fe415a20234b 87B
271520b1b69b3d5f2f166bbb28a8df741fb97c 145B
28563c0720d79974683a603e3dc53f35260aec 677B
2869f9c0d1077902cbd9c9f6dbabb732aeabb4 1KB
28ef8a3499fffb9f00a59b499239bfec44711c 181B
29fa6d62fb860a4a75633204294a887a058c80 146B
2c45e40ddb269c9234231d605fcbd8e29cb862 283B
2cdfc6aee338eb8e6256799ce409f5910fe186 124B
2d11f09c9de392d1433a1c0b89a86ab0205558 214B
2db05b4ee1eac3cffc0ce586bf1c650ce67925 123B
2dc5b1af3369873f453d37c803844f25f4a58b 959B
2e35d1622d8adfb036d311c72bf48d9b3ff085 146B
2e687288f73abf59ebffc31f83270a5bb45b8e 428B
2e70acf1404f5e35cfae6acc16eef38459ca68 631B
2e9616fec5a297b39f2e367900dccbc29b1ae3 483B
2e9cbd199b4c6e2843ffcefbffdafee4b7213e 452B
2f5bf73c61f980653d57257704a5495834c36f 125B
2f63753e30de65460ed383e066cf853f0efdfd 560B
2fe0b73af1de38151bc31708cc68c74e3c6185 197B
301b6c69b6e807c6f4eb29ead30c8e8030145f 104B
307a01417682a94e702f9750fcd0c9ffac63d1 582B
3131032a8b4552bb57849739d1c2775835ee0e 433B
3152199101d817804a96450a51a5ac2a18bd49 287B
31d6282c743d22f059107331a843a7bf78c511 3KB
31d94c38e195aa0e1c65ee3239f20d54f8bfe8 568B
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
易小侠
- 粉丝: 6636
- 资源: 9万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 【新增】-110 -食堂薪酬体系设计方案.doc
- 【新增】-112 -私立学校薪酬福利方案.doc
- 【新增】-113 -通用薪酬绩效管理制度方案.doc
- 【新增】-117 -外贸业务薪资及提成方案(暂行).doc
- 【新增】-118 -万科房地产公司全套销售薪酬管理制度 (1).doc
- 【新增】-116 -外贸薪酬制度原版.doc
- 【新增】-124 -物业公司薪酬体系方案(1).doc
- 【新增】-121 -物业公司绩效考核及薪酬方案.doc
- 【新增】-125 -物业公司组织架构与薪酬设计(修订版).doc
- 【新增】-129 -新华医院薪酬方案设计报告.doc
- 【新增】-134 -信托投资公司薪酬设计方案.doc
- 【新增】-137 -学校食堂员工薪资方案.doc
- 【新增】-139 -药店薪酬体系设计方案.doc
- 【新增】-138 -学校薪酬体系设计方案.doc
- 基于matlab 的ofdm仿真 具体点 想要加好友 不同调制方式ofdm误码率分析
- 【新增】-142 -油田公司薪酬制度与薪酬体系设计方案.doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功