![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('Ο συγγραφέας �
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
2022最新网盘存储网站源码 (2000个子文件)
19e313954d38acd9143adb4fe87fbc8c 28B
1ffe3206d5cb5b5b5d73c48f52546412 14B
2367f175d960e61fe668b27c1f990018 17B
26658e92f46b3c93b49247b0d5214e86 26B
3cb52a6396ada0e1fb033cddc4d6c2c6 2KB
3ffdbb12bdc9965c0583d3629e5e4303 3KB
45e6db4d8ac70327d65287dba38dac15 17B
4ab9ff7b04ece1e6c572394e11049a5fc182acee 197B
507eaa2d1b7015401c2f2148dc95d377 28B
5ad9fed09dbbe885bcbcf7033653ce40 148B
70b03b33d1e948e2e03276a5e5d32475 28B
724f27b308fd1789ab31ab1628f7b4cd 28B
7e1c1cbfb2cd0ec17afcc740e949f0e4 28B
8e93a2c415d17663157eead208ffa6a5 28B
902718ab09fece9d38c5b1d1c6474d7e 19B
95085ecdf0eefb51a77697094d83ff2c 133B
98a32c3163088dce850f0874038bf3b9 3KB
9c1643a33fc4c65fdce16264bc400bd57d57a512 6KB
9d8594965e002edab6480d8a59465d0f 19B
ab19d5f4d140de360bf0d1778d5c6b0d 120B
ad3684febac17d825132afdbe8ee848c 4KB
ae7c8fed05ae90721143c789a72577e5 26B
ae8342ee034957797f74195fde62e6c0 26B
upgrade-carbon.bat 101B
更多源码.bat 25B
更多源码.bat 25B
symfony_debug.c 7KB
c600ef3aff38e8ed3d6b6d391e91fed1 21B
c64860377ddc9dca4928ce386246879e 19B
c88b2a4b4bfb821d46bfaa8c1b1d8eaf 28B
c91dbf31f340a67352482ba0075f2449 1KB
cf91245e86bd706104037a1152672d50 28B
web.config 914B
base.css 973KB
style.css 450KB
index.css 230KB
layui.css 78KB
video-js.css 48KB
ueditor.css 32KB
font-awesome.min.css 26KB
layer.css 13KB
swiper.css 13KB
vue.css 12KB
video.css 12KB
tagify.css 11KB
attachment.css 11KB
simplemde.css 11KB
image.css 10KB
layui.mobile.css 10KB
default-skin.css 8KB
laydate.css 7KB
shCoreDefault.css 7KB
iconfont.css 6KB
banner.css 5KB
banner.css 5KB
iframe.css 4KB
cropper.css 4KB
scrawl.css 3KB
style.css 2KB
photoswipe.css 2KB
codemirror.css 2KB
background.css 2KB
emotion.css 2KB
plain.css 1KB
allElements.css 1KB
code.css 1KB
dialogbase.css 1KB
legacy.css 1KB
template.css 955B
member.css 902B
member.css 902B
edittable.css 875B
css.css 872B
admin.css 800B
webuploader.css 426B
help.css 361B
ConfigForm.css 301B
toggle.css 220B
toggle.css 220B
style.css 123B
d7247017f333968b5b1340593781f29c 12B
dcf93abeca69895c030f757c59342fc3 144B
.php_cs.dist 1KB
phpstan.neon.dist 405B
安装教程.docx 12KB
安装教程.docx 12KB
安装教程.docx 12KB
e63517f24ad501b82d690ebed378b6f2 9KB
ea2e86760b968be78dd7703cfd383b13 26B
.editorconfig 259B
.editorconfig 259B
.env 215B
fontawesome-webfont.eot 69KB
iconfont.eot 46KB
8fbe5401aaf59676ae94a5ef9a42ad7b.eot 9KB
VideoJS.eot 7KB
env.example 220B
f21d4bda414df04eac1e7950029b26da 17B
f72f70abbc9db5dbaa19bd0da7b19c78 17B
fb43fbaac8fa8b81abf4c8c9aa3578bf 231B
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
行动之上
- 粉丝: 2276
- 资源: 931
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 【新增】-071 -科技公司薪酬体系设计方案.doc
- 【新增】-077 -零售药店薪酬管理方案.doc
- 【新增】-078 -零售终端店铺薪酬方案.doc
- 【新增】-079 -贸易公司销售薪酬方案.doc
- 【新增】-081 -某医院薪酬管理体系设计方案).doc
- 【新增】-080 -贸易公司薪酬与绩效考核方案.doc
- 【新增】-089 -汽车4S店岗位级别薪资方案.doc
- 【新增】-094 -汽车销售专营店绩效考核、薪酬制度.doc
- 【新增】-091 -汽车4S店薪酬制度(丰田).doc
- 【新增】-090 -汽车4S店薪酬方案(上海大众).doc
- 【新增】-085 -农业科技薪酬体系设计方案.doc
- 【新增】-097 -软件开发公司薪酬制度.doc
- 全开源跑腿小程序/智能派单/系统派单/同城配送/校园跑腿/预约取件/用户端+骑手端
- 【新增】-101 -生产制造薪酬体系方案.doc
- 【新增】-104 -食品公司薪酬方案.doc
- 【新增】-108 -食品生产企业薪酬福利制度.doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功