mirror of
https://github.com/danielstjules/Stringy.git
synced 2025-01-17 20:38:13 +01:00
1028 lines
71 KiB
HTML
1028 lines
71 KiB
HTML
<!doctype html>
|
||
<html>
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta http-equiv="X-UA-Compatible" content="chrome=1">
|
||
<title>Stringy by danielstjules</title>
|
||
|
||
<link rel="stylesheet" href="stylesheets/styles.css">
|
||
<link rel="stylesheet" href="stylesheets/pygment_trac.css">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
|
||
<!--[if lt IE 9]>
|
||
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
||
<![endif]-->
|
||
</head>
|
||
<body>
|
||
<div class="wrapper">
|
||
<header>
|
||
<h1>Stringy</h1>
|
||
<p>A PHP string manipulation library with multibyte support</p>
|
||
|
||
<p class="view"><a href="https://github.com/danielstjules/Stringy">View the Project on GitHub <small>danielstjules/Stringy</small></a></p>
|
||
|
||
|
||
<ul>
|
||
<li><a href="https://github.com/danielstjules/Stringy/zipball/master">Download <strong>ZIP File</strong></a></li>
|
||
<li><a href="https://github.com/danielstjules/Stringy/tarball/master">Download <strong>TAR Ball</strong></a></li>
|
||
<li><a href="https://github.com/danielstjules/Stringy">View On <strong>GitHub</strong></a></li>
|
||
</ul>
|
||
</header>
|
||
<section>
|
||
<p><img src="http://danielstjules.com/stringy/logo.png" alt="Stringy"></p>
|
||
|
||
<p>A PHP library with a variety of string manipulation functions with multibyte
|
||
support. Offers both OO method chaining and a procedural-style static wrapper.
|
||
Compatible with PHP 5.3+. Inspired by underscore.string.js.</p>
|
||
|
||
<p><a href="https://travis-ci.org/danielstjules/Stringy"><img src="https://travis-ci.org/danielstjules/Stringy.png" alt="Build Status"></a></p>
|
||
|
||
<ul>
|
||
<li><a href="#requiringloading">Requiring/Loading</a></li>
|
||
<li><a href="#oo-and-procedural">OO and Procedural</a></li>
|
||
<li><a href="#implemented-interfaces">Implemented Interfaces</a></li>
|
||
<li>
|
||
<a href="#methods">Methods</a>
|
||
|
||
<ul>
|
||
<li><a href="#at">at</a></li>
|
||
<li><a href="#camelize">camelize</a></li>
|
||
<li><a href="#chars">chars</a></li>
|
||
<li><a href="#collapsewhitespace">collapseWhitespace</a></li>
|
||
<li><a href="#contains">contains</a></li>
|
||
<li><a href="#countsubstr">countSubstr</a></li>
|
||
<li><a href="#create">create</a></li>
|
||
<li><a href="#dasherize">dasherize</a></li>
|
||
<li><a href="#endswith">endsWith</a></li>
|
||
<li><a href="#ensureleft">ensureLeft</a></li>
|
||
<li><a href="#ensureright">ensureRight</a></li>
|
||
<li><a href="#first">first</a></li>
|
||
<li><a href="#getencoding">getEncoding</a></li>
|
||
<li><a href="#humanize">humanize</a></li>
|
||
<li><a href="#insert">insert</a></li>
|
||
<li><a href="#isalpha">isAlpha</a></li>
|
||
<li><a href="#isalphanumeric">isAlphanumeric</a></li>
|
||
<li><a href="#isblank">isBlank</a></li>
|
||
<li><a href="#ishexadecimal">isHexadecimal</a></li>
|
||
<li><a href="#isjson">isJson</a></li>
|
||
<li><a href="#islowercase">isLowerCase</a></li>
|
||
<li><a href="#isserialized">isSerialized</a></li>
|
||
<li><a href="#isuppercase">isUpperCase</a></li>
|
||
<li><a href="#last">last</a></li>
|
||
<li><a href="#length">length</a></li>
|
||
<li><a href="#longestcommonprefix">longestCommonPrefix</a></li>
|
||
<li><a href="#longestcommonsuffix">longestCommonSuffix</a></li>
|
||
<li><a href="#longestcommonsubstring">longestCommonSubstring</a></li>
|
||
<li><a href="#lowercasefirst">lowerCaseFirst</a></li>
|
||
<li><a href="#pad">pad</a></li>
|
||
<li><a href="#padboth">padBoth</a></li>
|
||
<li><a href="#padleft">padLeft</a></li>
|
||
<li><a href="#padright">padRight</a></li>
|
||
<li><a href="#regexreplace">regexReplace</a></li>
|
||
<li><a href="#removeleft">removeLeft</a></li>
|
||
<li><a href="#removeright">removeRight</a></li>
|
||
<li><a href="#replace">replace</a></li>
|
||
<li><a href="#reverse">reverse</a></li>
|
||
<li><a href="#safetruncate">safeTruncate</a></li>
|
||
<li><a href="#shuffle">shuffle</a></li>
|
||
<li><a href="#slugify">slugify</a></li>
|
||
<li><a href="#startswith">startsWith</a></li>
|
||
<li><a href="#substr">substr</a></li>
|
||
<li><a href="#surround">surround</a></li>
|
||
<li><a href="#swapcase">swapCase</a></li>
|
||
<li><a href="#tidy">tidy</a></li>
|
||
<li><a href="#titleize">titleize</a></li>
|
||
<li><a href="#toascii">toAscii</a></li>
|
||
<li><a href="#tolowercase">toLowerCase</a></li>
|
||
<li><a href="#tospaces">toSpaces</a></li>
|
||
<li><a href="#totabs">toTabs</a></li>
|
||
<li><a href="#touppercase">toUpperCase</a></li>
|
||
<li><a href="#trim">trim</a></li>
|
||
<li><a href="#truncate">truncate</a></li>
|
||
<li><a href="#underscored">underscored</a></li>
|
||
<li><a href="#uppercamelize">upperCamelize</a></li>
|
||
<li><a href="#uppercasefirst">upperCaseFirst</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a href="#links">Links</a></li>
|
||
<li><a href="#tests">Tests</a></li>
|
||
<li><a href="#license">License</a></li>
|
||
</ul><h2>
|
||
<a name="requiringloading" class="anchor" href="#requiringloading"><span class="octicon octicon-link"></span></a>Requiring/Loading</h2>
|
||
|
||
<p>If you're using Composer to manage dependencies, you can include the following
|
||
in your composer.json file:</p>
|
||
|
||
<pre><code>"require": {
|
||
"danielstjules/stringy": "dev-master"
|
||
}
|
||
</code></pre>
|
||
|
||
<p>Then, after running <code>composer update</code> or <code>php composer.phar update</code>, you can
|
||
load the class using Composer's autoloading:</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="k">require</span> <span class="s1">'vendor/autoload.php'</span><span class="p">;</span>
|
||
</pre></div>
|
||
|
||
<p>Otherwise, you can simply require the file directly:</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="k">require_once</span> <span class="s1">'path/to/Stringy/src/Stringy.php'</span><span class="p">;</span>
|
||
<span class="c1">// or</span>
|
||
<span class="k">require_once</span> <span class="s1">'path/to/Stringy/src/StaticStringy.php'</span><span class="p">;</span>
|
||
</pre></div>
|
||
|
||
<p>And in either case, I'd suggest using an alias.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="k">use</span> <span class="nx">Stringy\Stringy</span> <span class="k">as</span> <span class="nx">S</span><span class="p">;</span>
|
||
<span class="c1">// or</span>
|
||
<span class="k">use</span> <span class="nx">Stringy\StaticStringy</span> <span class="k">as</span> <span class="nx">S</span><span class="p">;</span>
|
||
</pre></div>
|
||
|
||
<h2>
|
||
<a name="oo-and-procedural" class="anchor" href="#oo-and-procedural"><span class="octicon octicon-link"></span></a>OO and Procedural</h2>
|
||
|
||
<p>The library offers both OO method chaining with <code>Stringy\Stringy</code>, as well as
|
||
procedural-style static method calls with <code>Stringy\StaticStringy</code>. An example
|
||
of the former is the following:</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="k">use</span> <span class="nx">Stringy\Stringy</span> <span class="k">as</span> <span class="nx">S</span><span class="p">;</span>
|
||
<span class="k">echo</span> <span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'Fòô Bàř'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">)</span><span class="o">-></span><span class="na">collapseWhitespace</span><span class="p">()</span><span class="o">-></span><span class="na">swapCase</span><span class="p">();</span> <span class="c1">// 'fÒÔ bÀŘ'</span>
|
||
</pre></div>
|
||
|
||
<p><code>Stringy\Stringy</code> has a __toString() method, which returns the current string
|
||
when the object is used in a string context, ie:
|
||
<code>(string) S::create('foo') // 'foo'</code></p>
|
||
|
||
<p>Using the static wrapper, an alternative is the following:</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="k">use</span> <span class="nx">Stringy\StaticStringy</span> <span class="k">as</span> <span class="nx">S</span><span class="p">;</span>
|
||
<span class="nv">$string</span> <span class="o">=</span> <span class="nx">S</span><span class="o">::</span><span class="na">collapseWhitespace</span><span class="p">(</span><span class="s1">'Fòô Bàř'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">);</span>
|
||
<span class="k">echo</span> <span class="nx">S</span><span class="o">::</span><span class="na">swapCase</span><span class="p">(</span><span class="nv">$string</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">);</span> <span class="c1">// 'fÒÔ bÀŘ'</span>
|
||
</pre></div>
|
||
|
||
<h2>
|
||
<a name="implemented-interfaces" class="anchor" href="#implemented-interfaces"><span class="octicon octicon-link"></span></a>Implemented Interfaces</h2>
|
||
|
||
<p><code>Stringy\Stringy</code> implements the <code>IteratorAggregate</code> interface, meaning that
|
||
<code>foreach</code> can be used with an instance of the class:</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nv">$stringy</span> <span class="o">=</span> <span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'Fòô Bàř'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">);</span>
|
||
<span class="k">foreach</span> <span class="p">(</span><span class="nv">$stringy</span> <span class="k">as</span> <span class="nv">$char</span><span class="p">)</span> <span class="p">{</span>
|
||
<span class="k">echo</span> <span class="nv">$char</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
<span class="c1">// 'Fòô Bàř'</span>
|
||
</pre></div>
|
||
|
||
<p>It implements the <code>Countable</code> interface, enabling the use of <code>count()</code> to
|
||
retrieve the number of characters in the string:</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nv">$stringy</span> <span class="o">=</span> <span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'Fòô'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">);</span>
|
||
<span class="nb">count</span><span class="p">(</span><span class="nv">$stringy</span><span class="p">);</span> <span class="c1">// 3</span>
|
||
</pre></div>
|
||
|
||
<p>Furthermore, the <code>ArrayAccess</code> interface has been implemented. As a result,
|
||
<code>isset()</code> can be used to check if a character at a specific index exists. And
|
||
since <code>Stringy\Stringy</code> is immutable, any call to <code>offsetSet</code> or <code>offsetUnset</code>
|
||
will throw an exception. <code>offsetGet</code> has been implemented, however, and accepts
|
||
both positive and negative indexes. Invalid indexes result in an
|
||
<code>OutOfBoundsException</code>.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nv">$stringy</span> <span class="o">=</span> <span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'Bàř'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">);</span>
|
||
<span class="k">echo</span> <span class="nv">$stringy</span><span class="p">[</span><span class="mi">2</span><span class="p">];</span> <span class="c1">// 'ř'</span>
|
||
<span class="k">echo</span> <span class="nv">$stringy</span><span class="p">[</span><span class="o">-</span><span class="mi">2</span><span class="p">];</span> <span class="c1">// 'à'</span>
|
||
<span class="nb">isset</span><span class="p">(</span><span class="nv">$stringy</span><span class="p">[</span><span class="o">-</span><span class="mi">4</span><span class="p">]);</span> <span class="c1">// false</span>
|
||
|
||
<span class="nv">$stringy</span><span class="p">[</span><span class="mi">3</span><span class="p">];</span> <span class="c1">// OutOfBoundsException</span>
|
||
<span class="nv">$stringy</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="s1">'a'</span><span class="p">;</span> <span class="c1">// Exception</span>
|
||
</pre></div>
|
||
|
||
<h2>
|
||
<a name="methods" class="anchor" href="#methods"><span class="octicon octicon-link"></span></a>Methods</h2>
|
||
|
||
<p>In the list below, any static method other than S::create refers to a method in
|
||
<code>Stringy\StaticStringy</code>. For all others, they're found in <code>Stringy\Stringy</code>.
|
||
Furthermore, all methods that return a Stringy object or string do not modify
|
||
the original. Stringy objects are immutable.</p>
|
||
|
||
<p><em>Note: If <code>$encoding</code> is not given, it defaults to <code>mb_internal_encoding()</code>.</em></p>
|
||
|
||
<h4>
|
||
<a name="at" class="anchor" href="#at"><span class="octicon octicon-link"></span></a>at</h4>
|
||
|
||
<p>$stringy->at(int $index)</p>
|
||
|
||
<p>S::at(int $index [, string $encoding ])</p>
|
||
|
||
<p>Returns the character at $index, with indexes starting at 0.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'fòô bàř'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">)</span><span class="o">-></span><span class="na">at</span><span class="p">(</span><span class="mi">6</span><span class="p">);</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">at</span><span class="p">(</span><span class="s1">'fòô bàř'</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">);</span> <span class="c1">// 'ř'</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="camelize" class="anchor" href="#camelize"><span class="octicon octicon-link"></span></a>camelize</h4>
|
||
|
||
<p>$stringy->camelize();</p>
|
||
|
||
<p>S::camelize(string $str [, string $encoding ])</p>
|
||
|
||
<p>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.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'Camel-Case'</span><span class="p">)</span><span class="o">-></span><span class="na">camelize</span><span class="p">();</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">camelize</span><span class="p">(</span><span class="s1">'Camel-Case'</span><span class="p">);</span> <span class="c1">// 'camelCase'</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="chars" class="anchor" href="#chars"><span class="octicon octicon-link"></span></a>chars</h4>
|
||
|
||
<p>$stringy->chars();</p>
|
||
|
||
<p>S::chars(string $str [, string $encoding ])</p>
|
||
|
||
<p>Returns an array consisting of the characters in the string.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'Fòô Bàř'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">)</span><span class="o">-></span><span class="na">chars</span><span class="p">();</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">chars</span><span class="p">(</span><span class="s1">'Fòô Bàř'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">);</span> <span class="c1">// array(F', 'ò', 'ô', ' ', 'B', 'à', 'ř')</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="collapsewhitespace" class="anchor" href="#collapsewhitespace"><span class="octicon octicon-link"></span></a>collapseWhitespace</h4>
|
||
|
||
<p>$stringy->collapseWhitespace()</p>
|
||
|
||
<p>S::collapseWhitespace(string $str [, string $encoding ])</p>
|
||
|
||
<p>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.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">' Ο συγγραφέας '</span><span class="p">)</span><span class="o">-></span><span class="na">collapseWhitespace</span><span class="p">();</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">collapseWhitespace</span><span class="p">(</span><span class="s1">' Ο συγγραφέας '</span><span class="p">);</span> <span class="c1">// 'Ο συγγραφέας'</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="contains" class="anchor" href="#contains"><span class="octicon octicon-link"></span></a>contains</h4>
|
||
|
||
<p>$stringy->contains(string $needle [, boolean $caseSensitive = true ])</p>
|
||
|
||
<p>S::contains(string $haystack, string $needle [, boolean $caseSensitive = true [, string $encoding ]])</p>
|
||
|
||
<p>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.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'Ο συγγραφέας είπε'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">)</span><span class="o">-></span><span class="na">contains</span><span class="p">(</span><span class="s1">'συγγραφέας'</span><span class="p">);</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">contains</span><span class="p">(</span><span class="s1">'Ο συγγραφέας είπε'</span><span class="p">,</span> <span class="s1">'συγγραφέας'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">);</span> <span class="c1">// true</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="countsubstr" class="anchor" href="#countsubstr"><span class="octicon octicon-link"></span></a>countSubstr</h4>
|
||
|
||
<p>$stringy->countSubstr(string $substring [, boolean $caseSensitive = true ])</p>
|
||
|
||
<p>S::countSubstr(string $str, string $substring [, boolean $caseSensitive = true [, string $encoding ]])</p>
|
||
|
||
<p>Returns the number of occurrences of $substring in the given string.
|
||
By default, the comparison is case-sensitive, but can be made insensitive
|
||
by setting $caseSensitive to false.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'Ο συγγραφέας είπε'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">)</span><span class="o">-></span><span class="na">countSubstr</span><span class="p">(</span><span class="s1">'α'</span><span class="p">);</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">countSubstr</span><span class="p">(</span><span class="s1">'Ο συγγραφέας είπε'</span><span class="p">,</span> <span class="s1">'α'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">);</span> <span class="c1">// 2</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="create" class="anchor" href="#create"><span class="octicon octicon-link"></span></a>create</h4>
|
||
|
||
<p>S::create(mixed $str, [, $encoding ])</p>
|
||
|
||
<p>Creates a Stringy object and assigns both str and encoding properties
|
||
the supplied values. $str is cast to a string prior to assignment, and if
|
||
$encoding is not specified, it defaults to mb_internal_encoding(). It
|
||
then returns the initialized object. Throws an InvalidArgumentException
|
||
if the first argument is an array or object without a __toString method.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nv">$stringy</span> <span class="o">=</span> <span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'fòô bàř'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">);</span> <span class="c1">// 'fòô bàř'</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="dasherize" class="anchor" href="#dasherize"><span class="octicon octicon-link"></span></a>dasherize</h4>
|
||
|
||
<p>$stringy->dasherize();</p>
|
||
|
||
<p>S::dasherize(string $str [, string $encoding ])</p>
|
||
|
||
<p>Returns a lowercase and trimmed string separated by dashes. Dashes are
|
||
inserted before uppercase characters (with the exception of the first
|
||
character of the string), and in place of spaces as well as underscores.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'TestDCase'</span><span class="p">)</span><span class="o">-></span><span class="na">dasherize</span><span class="p">();</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">dasherize</span><span class="p">(</span><span class="s1">'TestDCase'</span><span class="p">);</span> <span class="c1">// 'test-d-case'</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="endswith" class="anchor" href="#endswith"><span class="octicon octicon-link"></span></a>endsWith</h4>
|
||
|
||
<p>$stringy->endsWith(string $substring [, boolean $caseSensitive = true ])</p>
|
||
|
||
<p>S::endsWith(string $str, string $substring [, boolean $caseSensitive = true [, string $encoding ]])</p>
|
||
|
||
<p>Returns true if the string ends with $substring, false otherwise. By
|
||
default, the comparison is case-sensitive, but can be made insensitive by
|
||
setting $caseSensitive to false.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'FÒÔ bàřs'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">)</span><span class="o">-></span><span class="na">endsWith</span><span class="p">(</span><span class="s1">'àřs'</span><span class="p">,</span> <span class="k">true</span><span class="p">);</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">endsWith</span><span class="p">(</span><span class="s1">'FÒÔ bàřs'</span><span class="p">,</span> <span class="s1">'àřs'</span><span class="p">,</span> <span class="k">true</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">);</span> <span class="c1">// true</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="ensureleft" class="anchor" href="#ensureleft"><span class="octicon octicon-link"></span></a>ensureLeft</h4>
|
||
|
||
<p>$stringy->ensureLeft(string $substring)</p>
|
||
|
||
<p>S::ensureLeft(string $substring [, string $encoding ])</p>
|
||
|
||
<p>Ensures that the string begins with $substring. If it doesn't, it's prepended.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'foobar'</span><span class="p">)</span><span class="o">-></span><span class="na">ensureLeft</span><span class="p">(</span><span class="s1">'http://'</span><span class="p">);</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">ensureLeft</span><span class="p">(</span><span class="s1">'foobar'</span><span class="p">,</span> <span class="s1">'http://'</span><span class="p">);</span> <span class="c1">// 'http://foobar'</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="ensureright" class="anchor" href="#ensureright"><span class="octicon octicon-link"></span></a>ensureRight</h4>
|
||
|
||
<p>$stringy->ensureRight(string $substring)</p>
|
||
|
||
<p>S::ensureRight(string $substring [, string $encoding ])</p>
|
||
|
||
<p>Ensures that the string begins with $substring. If it doesn't, it's appended.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'foobar'</span><span class="p">)</span><span class="o">-></span><span class="na">ensureRight</span><span class="p">(</span><span class="s1">'.com'</span><span class="p">);</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">ensureRight</span><span class="p">(</span><span class="s1">'foobar'</span><span class="p">,</span> <span class="s1">'.com'</span><span class="p">);</span> <span class="c1">// 'foobar.com'</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="first" class="anchor" href="#first"><span class="octicon octicon-link"></span></a>first</h4>
|
||
|
||
<p>$stringy->first(int $n)</p>
|
||
|
||
<p>S::first(int $n [, string $encoding ])</p>
|
||
|
||
<p>Returns the first $n characters of the string.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'fòô bàř'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">)</span><span class="o">-></span><span class="na">first</span><span class="p">(</span><span class="mi">3</span><span class="p">);</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">first</span><span class="p">(</span><span class="s1">'fòô bàř'</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">);</span> <span class="c1">// 'fòô'</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="getencoding" class="anchor" href="#getencoding"><span class="octicon octicon-link"></span></a>getEncoding</h4>
|
||
|
||
<p>$stringy->getEncoding()</p>
|
||
|
||
<p>Returns the encoding used by the Stringy object.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'fòô bàř'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">)</span><span class="o">-></span><span class="na">getEncoding</span><span class="p">();</span> <span class="c1">// 'UTF-8'</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="humanize" class="anchor" href="#humanize"><span class="octicon octicon-link"></span></a>humanize</h4>
|
||
|
||
<p>$stringy->humanize()</p>
|
||
|
||
<p>S::humanize(string $str [, string $encoding ])</p>
|
||
|
||
<p>Capitalizes the first word of the string, replaces underscores with
|
||
spaces, and strips '_id'.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'author_id'</span><span class="p">)</span><span class="o">-></span><span class="na">humanize</span><span class="p">();</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">humanize</span><span class="p">(</span><span class="s1">'author_id'</span><span class="p">);</span> <span class="c1">// 'Author'</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="insert" class="anchor" href="#insert"><span class="octicon octicon-link"></span></a>insert</h4>
|
||
|
||
<p>$stringy->insert(int $index, string $substring)</p>
|
||
|
||
<p>S::insert(string $str, int $index, string $substring [, string $encoding ])</p>
|
||
|
||
<p>Inserts $substring into the string at the $index provided.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'fòô bà'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">)</span><span class="o">-></span><span class="na">insert</span><span class="p">(</span><span class="s1">'ř'</span><span class="p">,</span> <span class="mi">6</span><span class="p">);</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">insert</span><span class="p">(</span><span class="s1">'fòô bà'</span><span class="p">,</span> <span class="s1">'ř'</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">);</span> <span class="c1">// 'fòô bàř'</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="isalpha" class="anchor" href="#isalpha"><span class="octicon octicon-link"></span></a>isAlpha</h4>
|
||
|
||
<p>$stringy->isAlpha()</p>
|
||
|
||
<p>S::isAlpha(string $str [, string $encoding ])</p>
|
||
|
||
<p>Returns true if the string contains only alphabetic chars, false otherwise.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'丹尼爾'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">)</span><span class="o">-></span><span class="na">isAlpha</span><span class="p">();</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">isAlpha</span><span class="p">(</span><span class="s1">'丹尼爾'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">);</span> <span class="c1">// true</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="isalphanumeric" class="anchor" href="#isalphanumeric"><span class="octicon octicon-link"></span></a>isAlphanumeric</h4>
|
||
|
||
<p>$stringy->isAlphanumeric()</p>
|
||
|
||
<p>S::isAlphanumeric(string $str [, string $encoding ])</p>
|
||
|
||
<p>Returns true if the string contains only alphabetic and numeric chars, false
|
||
otherwise.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'دانيال1'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">)</span><span class="o">-></span><span class="na">isAlphanumeric</span><span class="p">();</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">isAlphanumeric</span><span class="p">(</span><span class="s1">'دانيال1'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">);</span> <span class="c1">// true</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="isblank" class="anchor" href="#isblank"><span class="octicon octicon-link"></span></a>isBlank</h4>
|
||
|
||
<p>$stringy->isBlank()</p>
|
||
|
||
<p>S::isBlank(string $str [, string $encoding ])</p>
|
||
|
||
<p>Returns true if the string contains only whitespace chars, false otherwise.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s2">"</span><span class="se">\n\t</span><span class="s2"> \v\f"</span><span class="p">)</span><span class="o">-></span><span class="na">isBlank</span><span class="p">();</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">isBlank</span><span class="p">(</span><span class="s2">"</span><span class="se">\n\t</span><span class="s2"> \v\f"</span><span class="p">);</span> <span class="c1">// true</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="ishexadecimal" class="anchor" href="#ishexadecimal"><span class="octicon octicon-link"></span></a>isHexadecimal</h4>
|
||
|
||
<p>$stringy->isHexadecimal()</p>
|
||
|
||
<p>S::isHexadecimal(string $str [, string $encoding ])</p>
|
||
|
||
<p>Returns true if the string contains only hexadecimal chars, false otherwise.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'A102F'</span><span class="p">)</span><span class="o">-></span><span class="na">isHexadecimal</span><span class="p">();</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">isHexadecimal</span><span class="p">(</span><span class="s1">'A102F'</span><span class="p">);</span> <span class="c1">// true</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="isjson" class="anchor" href="#isjson"><span class="octicon octicon-link"></span></a>isJson</h4>
|
||
|
||
<p>$stringy->isJson()</p>
|
||
|
||
<p>S::isJson(string $str [, string $encoding ])</p>
|
||
|
||
<p>Returns true if the string is JSON, false otherwise.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'{"foo":"bar"}'</span><span class="p">)</span><span class="o">-></span><span class="na">isJson</span><span class="p">();</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">isJson</span><span class="p">(</span><span class="s1">'{"foo":"bar"}'</span><span class="p">);</span> <span class="c1">// true</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="islowercase" class="anchor" href="#islowercase"><span class="octicon octicon-link"></span></a>isLowerCase</h4>
|
||
|
||
<p>$stringy->isLowerCase()</p>
|
||
|
||
<p>S::isLowerCase(string $str [, string $encoding ])</p>
|
||
|
||
<p>Returns true if the string contains only lower case chars, false otherwise.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'fòô bàř'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">)</span><span class="o">-></span><span class="na">isLowerCase</span><span class="p">();</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">isLowerCase</span><span class="p">(</span><span class="s1">'fòô bàř'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">);</span> <span class="c1">// true</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="isserialized" class="anchor" href="#isserialized"><span class="octicon octicon-link"></span></a>isSerialized</h4>
|
||
|
||
<p>$stringy->isSerialized()</p>
|
||
|
||
<p>S::isSerialized(string $str [, string $encoding ])</p>
|
||
|
||
<p>Returns true if the string is serialized, false otherwise.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'a:1:{s:3:"foo";s:3:"bar";}'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">)</span><span class="o">-></span><span class="na">isSerialized</span><span class="p">();</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">isSerialized</span><span class="p">(</span><span class="s1">'a:1:{s:3:"foo";s:3:"bar";}'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">);</span> <span class="c1">// true</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="isuppercase" class="anchor" href="#isuppercase"><span class="octicon octicon-link"></span></a>isUpperCase</h4>
|
||
|
||
<p>$stringy->isUpperCase()</p>
|
||
|
||
<p>S::isUpperCase(string $str [, string $encoding ])</p>
|
||
|
||
<p>Returns true if the string contains only upper case chars, false otherwise.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'FÒÔBÀŘ'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">)</span><span class="o">-></span><span class="na">isUpperCase</span><span class="p">();</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">isUpperCase</span><span class="p">(</span><span class="s1">'FÒÔBÀŘ'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">);</span> <span class="c1">// true</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="last" class="anchor" href="#last"><span class="octicon octicon-link"></span></a>last</h4>
|
||
|
||
<p>$stringy->last(int $n)</p>
|
||
|
||
<p>S::last(int $n [, string $encoding ])</p>
|
||
|
||
<p>Returns the last $n characters of the string.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'fòô bàř'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">)</span><span class="o">-></span><span class="na">last</span><span class="p">(</span><span class="mi">3</span><span class="p">);</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">last</span><span class="p">(</span><span class="s1">'fòô bàř'</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">);</span> <span class="c1">// 'bàř'</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="length" class="anchor" href="#length"><span class="octicon octicon-link"></span></a>length</h4>
|
||
|
||
<p>$stringy->length()</p>
|
||
|
||
<p>S::length(string $str [, string $encoding ])</p>
|
||
|
||
<p>Returns the length of the string. An alias for PHP's mb_strlen() function.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'fòô bàř'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">)</span><span class="o">-></span><span class="na">length</span><span class="p">();</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">length</span><span class="p">(</span><span class="s1">'fòô bàř'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">);</span> <span class="c1">// 7</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="longestcommonprefix" class="anchor" href="#longestcommonprefix"><span class="octicon octicon-link"></span></a>longestCommonPrefix</h4>
|
||
|
||
<p>$stringy->longestCommonPrefix(string $otherStr)</p>
|
||
|
||
<p>S::longestCommonPrefix(string $str, string $otherStr [, $encoding ])</p>
|
||
|
||
<p>Returns the longest common prefix between the string and $otherStr.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'fòô bar'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">)</span><span class="o">-></span><span class="na">longestCommonPrefix</span><span class="p">(</span><span class="s1">'fòr bar'</span><span class="p">);</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">longestCommonPrefix</span><span class="p">(</span><span class="s1">'fòô bar'</span><span class="p">,</span> <span class="s1">'fòr bar'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">);</span> <span class="c1">// 'fò'</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="longestcommonsuffix" class="anchor" href="#longestcommonsuffix"><span class="octicon octicon-link"></span></a>longestCommonSuffix</h4>
|
||
|
||
<p>$stringy->longestCommonSuffix(string $otherStr)</p>
|
||
|
||
<p>S::longestCommonSuffix(string $str, string $otherStr [, $encoding ])</p>
|
||
|
||
<p>Returns the longest common suffix between the string and $otherStr.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'fòô bàř'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">)</span><span class="o">-></span><span class="na">longestCommonSuffix</span><span class="p">(</span><span class="s1">'fòr bàř'</span><span class="p">);</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">longestCommonSuffix</span><span class="p">(</span><span class="s1">'fòô bàř'</span><span class="p">,</span> <span class="s1">'fòr bàř'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">);</span> <span class="c1">// ' bàř'</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="longestcommonsubstring" class="anchor" href="#longestcommonsubstring"><span class="octicon octicon-link"></span></a>longestCommonSubstring</h4>
|
||
|
||
<p>$stringy->longestCommonSubstring(string $otherStr)</p>
|
||
|
||
<p>S::longestCommonSubstring(string $str, string $otherStr [, $encoding ])</p>
|
||
|
||
<p>Returns the longest common substring between the string and $otherStr. In the
|
||
case of ties, it returns that which occurs first.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'foo bar'</span><span class="p">)</span><span class="o">-></span><span class="na">longestCommonSubstring</span><span class="p">(</span><span class="s1">'boo far'</span><span class="p">);</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">longestCommonSubstring</span><span class="p">(</span><span class="s1">'foo bar'</span><span class="p">,</span> <span class="s1">'boo far'</span><span class="p">);</span> <span class="c1">// 'oo '</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="lowercasefirst" class="anchor" href="#lowercasefirst"><span class="octicon octicon-link"></span></a>lowerCaseFirst</h4>
|
||
|
||
<p>$stringy->lowerCaseFirst();</p>
|
||
|
||
<p>S::lowerCaseFirst(string $str [, string $encoding ])</p>
|
||
|
||
<p>Converts the first character of the supplied string to lower case.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'Σ test'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">)</span><span class="o">-></span><span class="na">lowerCaseFirst</span><span class="p">();</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">lowerCaseFirst</span><span class="p">(</span><span class="s1">'Σ test'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">);</span> <span class="c1">// 'σ test'</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="pad" class="anchor" href="#pad"><span class="octicon octicon-link"></span></a>pad</h4>
|
||
|
||
<p>$stringy->pad(int $length [, string $padStr = ' ' [, string $padType = 'right' ]])</p>
|
||
|
||
<p>S::pad(string $str , int $length [, string $padStr = ' ' [, string $padType = 'right' [, string $encoding ]]])</p>
|
||
|
||
<p>Pads the string to a given length with $padStr. If length is less than
|
||
or equal to the length of the string, no padding takes places. The default
|
||
string used for padding is a space, and the default type (one of 'left',
|
||
'right', 'both') is 'right'. Throws an InvalidArgumentException if
|
||
$padType isn't one of those 3 values.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'fòô bàř'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">)</span><span class="o">-></span><span class="na">pad</span><span class="p">(</span> <span class="mi">10</span><span class="p">,</span> <span class="s1">'¬ø'</span><span class="p">,</span> <span class="s1">'left'</span><span class="p">);</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">pad</span><span class="p">(</span><span class="s1">'fòô bàř'</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="s1">'¬ø'</span><span class="p">,</span> <span class="s1">'left'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">);</span> <span class="c1">// '¬ø¬fòô bàř'</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="padboth" class="anchor" href="#padboth"><span class="octicon octicon-link"></span></a>padBoth</h4>
|
||
|
||
<p>$stringy->padBoth(int $length [, string $padStr = ' ' ])</p>
|
||
|
||
<p>S::padBoth(string $str , int $length [, string $padStr = ' ' [, string $encoding ]])</p>
|
||
|
||
<p>Returns a new string of a given length such that both sides of the string
|
||
string are padded. Alias for pad() with a $padType of 'both'.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'foo bar'</span><span class="p">)</span><span class="o">-></span><span class="na">padBoth</span><span class="p">(</span><span class="mi">9</span><span class="p">,</span> <span class="s1">' '</span><span class="p">);</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">padBoth</span><span class="p">(</span><span class="s1">'foo bar'</span><span class="p">,</span> <span class="mi">9</span><span class="p">,</span> <span class="s1">' '</span><span class="p">);</span> <span class="c1">// ' foo bar '</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="padleft" class="anchor" href="#padleft"><span class="octicon octicon-link"></span></a>padLeft</h4>
|
||
|
||
<p>$stringy->padLeft(int $length [, string $padStr = ' ' ])</p>
|
||
|
||
<p>S::padLeft(string $str , int $length [, string $padStr = ' ' [, string $encoding ]])</p>
|
||
|
||
<p>Returns a new string of a given length such that the beginning of the
|
||
string is padded. Alias for pad() with a $padType of 'left'.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="nv">$str</span><span class="p">,</span> <span class="nv">$encoding</span><span class="p">)</span><span class="o">-></span><span class="na">padLeft</span><span class="p">(</span><span class="nv">$length</span><span class="p">,</span> <span class="nv">$padStr</span><span class="p">);</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">padLeft</span><span class="p">(</span><span class="s1">'foo bar'</span><span class="p">,</span> <span class="mi">9</span><span class="p">,</span> <span class="s1">' '</span><span class="p">);</span> <span class="c1">// ' foo bar'</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="padright" class="anchor" href="#padright"><span class="octicon octicon-link"></span></a>padRight</h4>
|
||
|
||
<p>$stringy->padRight(int $length [, string $padStr = ' ' ])</p>
|
||
|
||
<p>S::padRight(string $str , int $length [, string $padStr = ' ' [, string $encoding ]])</p>
|
||
|
||
<p>Returns a new string of a given length such that the end of the string is
|
||
padded. Alias for pad() with a $padType of 'right'.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'foo bar'</span><span class="p">)</span><span class="o">-></span><span class="na">padRight</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="s1">'_*'</span><span class="p">);</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">padRight</span><span class="p">(</span><span class="s1">'foo bar'</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="s1">'_*'</span><span class="p">);</span> <span class="c1">// 'foo bar_*_'</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="regexreplace" class="anchor" href="#regexreplace"><span class="octicon octicon-link"></span></a>regexReplace</h4>
|
||
|
||
<p>$stringy->regexReplace(string $pattern, string $replacement [, string $options = 'msr'])</p>
|
||
|
||
<p>S::regexReplace(string $str, string $pattern, string $replacement [, string $options = 'msr' [, string $encoding ]])</p>
|
||
|
||
<p>Replaces all occurrences of $pattern in $str by $replacement. An alias
|
||
for mb_ereg_replace(). Note that the 'i' option with multibyte patterns
|
||
in mb_ereg_replace() requires PHP 5.4+. This is due to a lack of support
|
||
in the bundled version of Oniguruma in PHP 5.3.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'fòô '</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">)</span><span class="o">-></span><span class="na">regexReplace</span><span class="p">(</span><span class="s1">'f[òô]+\s'</span><span class="p">,</span> <span class="s1">'bàř'</span><span class="p">,</span> <span class="s1">'msr'</span><span class="p">);</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">regexReplace</span><span class="p">(</span><span class="s1">'fòô '</span><span class="p">,</span> <span class="s1">'f[òô]+\s'</span><span class="p">,</span> <span class="s1">'bàř'</span><span class="p">,</span> <span class="s1">'msr'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">);</span> <span class="c1">// 'bàř'</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="removeleft" class="anchor" href="#removeleft"><span class="octicon octicon-link"></span></a>removeLeft</h4>
|
||
|
||
<p>$stringy->removeLeft(string $substring)</p>
|
||
|
||
<p>S::removeLeft(string $str, string $substring [, string $encoding ])</p>
|
||
|
||
<p>Returns a new string with the prefix $substring removed, if present.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'fòô bàř'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">)</span><span class="o">-></span><span class="na">removeLeft</span><span class="p">(</span><span class="s1">'fòô '</span><span class="p">);</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">removeLeft</span><span class="p">(</span><span class="s1">'fòô bàř'</span><span class="p">,</span> <span class="s1">'fòô '</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">);</span> <span class="c1">// 'bàř'</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="removeright" class="anchor" href="#removeright"><span class="octicon octicon-link"></span></a>removeRight</h4>
|
||
|
||
<p>$stringy->removeRight(string $substring)</p>
|
||
|
||
<p>S::removeRight(string $str, string $substring [, string $encoding ])</p>
|
||
|
||
<p>Returns a new string with the suffix $substring removed, if present.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'fòô bàř'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">)</span><span class="o">-></span><span class="na">removeRight</span><span class="p">(</span><span class="s1">' bàř'</span><span class="p">);</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">removeRight</span><span class="p">(</span><span class="s1">'fòô bàř'</span><span class="p">,</span> <span class="s1">' bàř'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">);</span> <span class="c1">// 'fòô'</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="replace" class="anchor" href="#replace"><span class="octicon octicon-link"></span></a>replace</h4>
|
||
|
||
<p>$stringy->replace(string $search, string $replacement)</p>
|
||
|
||
<p>S::replace(string $str, string $search, string $replacement [, string $encoding ])</p>
|
||
|
||
<p>Replaces all occurrences of $search in $str by $replacement.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'fòô bàř fòô bàř'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">)</span><span class="o">-></span><span class="na">replace</span><span class="p">(</span><span class="s1">'fòô '</span><span class="p">,</span> <span class="s1">''</span><span class="p">);</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">replace</span><span class="p">(</span><span class="s1">'fòô bàř fòô bàř'</span><span class="p">,</span> <span class="s1">'fòô '</span><span class="p">,</span> <span class="s1">''</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">);</span> <span class="c1">// 'bàř bàř'</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="reverse" class="anchor" href="#reverse"><span class="octicon octicon-link"></span></a>reverse</h4>
|
||
|
||
<p>$stringy->reverse()</p>
|
||
|
||
<p>S::reverse(string $str, [, string $encoding ])</p>
|
||
|
||
<p>Returns a reversed string. A multibyte version of strrev().</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'fòô bàř'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">)</span><span class="o">-></span><span class="na">reverse</span><span class="p">();</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">reverse</span><span class="p">(</span><span class="s1">'fòô bàř'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">);</span> <span class="c1">// 'řàb ôòf'</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="safetruncate" class="anchor" href="#safetruncate"><span class="octicon octicon-link"></span></a>safeTruncate</h4>
|
||
|
||
<p>$stringy->safeTruncate(int $length, [, string $substring = '' ])</p>
|
||
|
||
<p>S::safeTruncate(string $str, int $length, [, string $substring = '' [, string $encoding ]])</p>
|
||
|
||
<p>Truncates the string to a given length, while ensuring that it does not
|
||
split words. If $substring is provided, and truncating occurs, the
|
||
string is further truncated so that the substring may be appended without
|
||
exceeding the desired length.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'What are your plans today?'</span><span class="p">)</span><span class="o">-></span><span class="na">safeTruncate</span><span class="p">(</span><span class="mi">22</span><span class="p">,</span> <span class="s1">'...'</span><span class="p">);</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">safeTruncate</span><span class="p">(</span><span class="s1">'What are your plans today?'</span><span class="p">,</span> <span class="mi">22</span><span class="p">,</span> <span class="s1">'...'</span><span class="p">);</span> <span class="c1">// 'What are your plans...'</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="shuffle" class="anchor" href="#shuffle"><span class="octicon octicon-link"></span></a>shuffle</h4>
|
||
|
||
<p>$stringy->shuffle()</p>
|
||
|
||
<p>S::shuffle(string $str [, string $encoding ])</p>
|
||
|
||
<p>A multibyte str_shuffle() function. It returns a string with its characters in
|
||
random order.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'fòô bàř'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">)</span><span class="o">-></span><span class="na">shuffle</span><span class="p">();</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">shuffle</span><span class="p">(</span><span class="s1">'fòô bàř'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">);</span> <span class="c1">// 'àôřb òf'</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="slugify" class="anchor" href="#slugify"><span class="octicon octicon-link"></span></a>slugify</h4>
|
||
|
||
<p>$stringy->slugify([ string $replacement = '-' ])</p>
|
||
|
||
<p>S::slugify(string $str [, string $replacement = '-' ])</p>
|
||
|
||
<p>Converts the string into an URL slug. This includes replacing non-ASCII
|
||
characters with their closest ASCII equivalents, removing remaining
|
||
non-ASCII and non-alphanumeric characters, and replacing whitespace with
|
||
$replacement. The replacement defaults to a single dash, and the string
|
||
is also converted to lowercase.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'Using strings like fòô bàř'</span><span class="p">)</span><span class="o">-></span><span class="na">slugify</span><span class="p">();</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">slugify</span><span class="p">(</span><span class="s1">'Using strings like fòô bàř'</span><span class="p">);</span> <span class="c1">// 'using-strings-like-foo-bar'</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="startswith" class="anchor" href="#startswith"><span class="octicon octicon-link"></span></a>startsWith</h4>
|
||
|
||
<p>$stringy->startsWith(string $substring [, boolean $caseSensitive = true ])</p>
|
||
|
||
<p>S::startsWith(string $str, string $substring [, boolean $caseSensitive = true [, string $encoding ]])</p>
|
||
|
||
<p>Returns true if the string begins with $substring, false otherwise.
|
||
By default, the comparison is case-sensitive, but can be made insensitive
|
||
by setting $caseSensitive to false.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'FÒÔ bàřs'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">)</span><span class="o">-></span><span class="na">startsWith</span><span class="p">(</span><span class="s1">'fòô bàř'</span><span class="p">,</span> <span class="k">false</span><span class="p">);</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">startsWith</span><span class="p">(</span><span class="s1">'FÒÔ bàřs'</span><span class="p">,</span> <span class="s1">'fòô bàř'</span><span class="p">,</span> <span class="k">false</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">);</span> <span class="c1">// true</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="substr" class="anchor" href="#substr"><span class="octicon octicon-link"></span></a>substr</h4>
|
||
|
||
<p>$stringy->substr(int $start [, int $length ])</p>
|
||
|
||
<p>S::substr(string $str, int $start [, int $length [, string $encoding ]])</p>
|
||
|
||
<p>Returns the substring beginning at $start with the specified $length.
|
||
It differs from the mb_substr() function in that providing a $length of
|
||
null will return the rest of the string, rather than an empty string.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'fòô bàř'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">)</span><span class="o">-></span><span class="na">substr</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">);</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">substr</span><span class="p">(</span><span class="s1">'fòô bàř'</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">);</span> <span class="c1">// 'ô b'</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="surround" class="anchor" href="#surround"><span class="octicon octicon-link"></span></a>surround</h4>
|
||
|
||
<p>$stringy->surround(string $substring)</p>
|
||
|
||
<p>S::surround(string $str, string $substring)</p>
|
||
|
||
<p>Surrounds a string with the given substring.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">' ͜ '</span><span class="p">)</span><span class="o">-></span><span class="na">surround</span><span class="p">(</span><span class="s1">'ʘ'</span><span class="p">);</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">surround</span><span class="p">(</span><span class="s1">' ͜ '</span><span class="p">,</span> <span class="s1">'ʘ'</span><span class="p">);</span> <span class="c1">// 'ʘ ͜ ʘ'</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="swapcase" class="anchor" href="#swapcase"><span class="octicon octicon-link"></span></a>swapCase</h4>
|
||
|
||
<p>$stringy->swapCase();</p>
|
||
|
||
<p>S::swapCase(string $str [, string $encoding ])</p>
|
||
|
||
<p>Returns a case swapped version of the string.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'Ντανιλ'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">)</span><span class="o">-></span><span class="na">swapCase</span><span class="p">();</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">swapCase</span><span class="p">(</span><span class="s1">'Ντανιλ'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">);</span> <span class="c1">// 'νΤΑΝΙΛ'</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="tidy" class="anchor" href="#tidy"><span class="octicon octicon-link"></span></a>tidy</h4>
|
||
|
||
<p>$stringy->tidy()</p>
|
||
|
||
<p>S::tidy(string $str)</p>
|
||
|
||
<p>Returns a string with smart quotes, ellipsis characters, and dashes from
|
||
Windows-1252 (commonly used in Word documents) replaced by their ASCII equivalents.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'“I see…”'</span><span class="p">)</span><span class="o">-></span><span class="na">tidy</span><span class="p">();</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">tidy</span><span class="p">(</span><span class="s1">'“I see…”'</span><span class="p">);</span> <span class="c1">// '"I see..."'</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="titleize" class="anchor" href="#titleize"><span class="octicon octicon-link"></span></a>titleize</h4>
|
||
|
||
<p>$stringy->titleize([ string $encoding ])</p>
|
||
|
||
<p>S::titleize(string $str [, array $ignore [, string $encoding ]])</p>
|
||
|
||
<p>Returns a trimmed string with the first letter of each word capitalized.
|
||
Ignores the case of other letters, preserving any acronyms. Also accepts
|
||
an array, $ignore, allowing you to list words not to be capitalized.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nv">$ignore</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span><span class="s1">'at'</span><span class="p">,</span> <span class="s1">'by'</span><span class="p">,</span> <span class="s1">'for'</span><span class="p">,</span> <span class="s1">'in'</span><span class="p">,</span> <span class="s1">'of'</span><span class="p">,</span> <span class="s1">'on'</span><span class="p">,</span> <span class="s1">'out'</span><span class="p">,</span> <span class="s1">'to'</span><span class="p">,</span> <span class="s1">'the'</span><span class="p">);</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'i like to watch DVDs at home'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">)</span><span class="o">-></span><span class="na">titleize</span><span class="p">(</span><span class="nv">$ignore</span><span class="p">);</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">titleize</span><span class="p">(</span><span class="s1">'i like to watch DVDs at home'</span><span class="p">,</span> <span class="nv">$ignore</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">);</span>
|
||
<span class="c1">// 'I Like to Watch DVDs at Home'</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="toascii" class="anchor" href="#toascii"><span class="octicon octicon-link"></span></a>toAscii</h4>
|
||
|
||
<p>$stringy->toAscii()</p>
|
||
|
||
<p>S::toAscii(string $str)</p>
|
||
|
||
<p>Returns an ASCII version of the string. A set of non-ASCII characters are
|
||
replaced with their closest ASCII counterparts, and the rest are removed.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'fòô bàř'</span><span class="p">)</span><span class="o">-></span><span class="na">toAscii</span><span class="p">();</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">toAscii</span><span class="p">(</span><span class="s1">'fòô bàř'</span><span class="p">);</span> <span class="c1">// 'foo bar'</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="tolowercase" class="anchor" href="#tolowercase"><span class="octicon octicon-link"></span></a>toLowerCase</h4>
|
||
|
||
<p>$stringy->toLowerCase()</p>
|
||
|
||
<p>S::toLowerCase(string $str [, string $encoding ])</p>
|
||
|
||
<p>Converts all characters in the string to lowercase. An alias for PHP's
|
||
mb_strtolower().</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'FÒÔ BÀŘ'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">)</span><span class="o">-></span><span class="na">toLowerCase</span><span class="p">();</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">toLowerCase</span><span class="p">(</span><span class="s1">'FÒÔ BÀŘ'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">);</span> <span class="c1">// 'fòô bàř'</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="tospaces" class="anchor" href="#tospaces"><span class="octicon octicon-link"></span></a>toSpaces</h4>
|
||
|
||
<p>$stringy->toSpaces([ tabLength = 4 ])</p>
|
||
|
||
<p>S::toSpaces(string $str, [, int $tabLength = 4 ])</p>
|
||
|
||
<p>Converts each tab in the string to some number of spaces, as defined by
|
||
$tabLength. By default, each tab is converted to 4 consecutive spaces.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">' String speech = "Hi"'</span><span class="p">)</span><span class="o">-></span><span class="na">toSpaces</span><span class="p">();</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">toSpaces</span><span class="p">(</span><span class="s1">' String speech = "Hi"'</span><span class="p">);</span> <span class="c1">// ' String speech = "Hi"'</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="totabs" class="anchor" href="#totabs"><span class="octicon octicon-link"></span></a>toTabs</h4>
|
||
|
||
<p>$stringy->toTabs([ tabLength = 4 ])</p>
|
||
|
||
<p>S::toTabs(string $str, [, int $tabLength = 4 ])</p>
|
||
|
||
<p>Converts each occurrence of some consecutive number of spaces, as defined
|
||
by $tabLength, to a tab. By default, each 4 consecutive spaces are
|
||
converted to a tab.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">' fòô bàř'</span><span class="p">)</span><span class="o">-></span><span class="na">toTabs</span><span class="p">();</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">toTabs</span><span class="p">(</span><span class="s1">' fòô bàř'</span><span class="p">);</span> <span class="c1">// ' fòô bàř'</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="touppercase" class="anchor" href="#touppercase"><span class="octicon octicon-link"></span></a>toUpperCase</h4>
|
||
|
||
<p>$stringy->toUpperCase()</p>
|
||
|
||
<p>S::toUpperCase(string $str [, string $encoding ])</p>
|
||
|
||
<p>Converts all characters in the string to uppercase. An alias for PHP's
|
||
mb_strtoupper().</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'fòô bàř'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">)</span><span class="o">-></span><span class="na">toUpperCase</span><span class="p">();</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">toUpperCase</span><span class="p">(</span><span class="s1">'fòô bàř'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">);</span> <span class="c1">// 'FÒÔ BÀŘ'</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="trim" class="anchor" href="#trim"><span class="octicon octicon-link"></span></a>trim</h4>
|
||
|
||
<p>$stringy->trim()</p>
|
||
|
||
<p>S::trim(string $str)</p>
|
||
|
||
<p>Returns the trimmed string. An alias for PHP's trim() function.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'fòô bàř'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">)</span><span class="o">-></span><span class="na">trim</span><span class="p">();</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">trim</span><span class="p">(</span><span class="s1">' fòô bàř '</span><span class="p">);</span> <span class="c1">// 'fòô bàř'</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="truncate" class="anchor" href="#truncate"><span class="octicon octicon-link"></span></a>truncate</h4>
|
||
|
||
<p>$stringy->truncate(int $length, [, string $substring = '' ])</p>
|
||
|
||
<p>S::truncate(string $str, int $length, [, string $substring = '' [, string $encoding ]])</p>
|
||
|
||
<p>Truncates the string to a given length. If $substring is provided, and
|
||
truncating occurs, the string is further truncated so that the substring
|
||
may be appended without exceeding the desired length.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'What are your plans today?'</span><span class="p">)</span><span class="o">-></span><span class="na">truncate</span><span class="p">(</span><span class="mi">19</span><span class="p">,</span> <span class="s1">'...'</span><span class="p">);</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">truncate</span><span class="p">(</span><span class="s1">'What are your plans today?'</span><span class="p">,</span> <span class="mi">19</span><span class="p">,</span> <span class="s1">'...'</span><span class="p">);</span> <span class="c1">// 'What are your pl...'</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="underscored" class="anchor" href="#underscored"><span class="octicon octicon-link"></span></a>underscored</h4>
|
||
|
||
<p>$stringy->underscored();</p>
|
||
|
||
<p>S::underscored(string $str [, string $encoding ])</p>
|
||
|
||
<p>Returns a lowercase and trimmed string separated by underscores.
|
||
Underscores are inserted before uppercase characters (with the exception
|
||
of the first character of the string), and in place of spaces as well as dashes.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'TestUCase'</span><span class="p">)</span><span class="o">-></span><span class="na">underscored</span><span class="p">();</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">underscored</span><span class="p">(</span><span class="s1">'TestUCase'</span><span class="p">);</span> <span class="c1">// 'test_u_case'</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="uppercamelize" class="anchor" href="#uppercamelize"><span class="octicon octicon-link"></span></a>upperCamelize</h4>
|
||
|
||
<p>$stringy->upperCamelize();</p>
|
||
|
||
<p>S::upperCamelize(string $str [, string $encoding ])</p>
|
||
|
||
<p>Returns an UpperCamelCase version of the supplied string. It trims
|
||
surrounding spaces, capitalizes letters following digits, spaces, dashes
|
||
and underscores, and removes spaces, dashes, underscores.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'Upper Camel-Case'</span><span class="p">)</span><span class="o">-></span><span class="na">upperCamelize</span><span class="p">();</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">upperCamelize</span><span class="p">(</span><span class="s1">'Upper Camel-Case'</span><span class="p">);</span> <span class="c1">// 'UpperCamelCase'</span>
|
||
</pre></div>
|
||
|
||
<h4>
|
||
<a name="uppercasefirst" class="anchor" href="#uppercasefirst"><span class="octicon octicon-link"></span></a>upperCaseFirst</h4>
|
||
|
||
<p>$stringy->upperCaseFirst();</p>
|
||
|
||
<p>S::upperCaseFirst(string $str [, string $encoding ])</p>
|
||
|
||
<p>Converts the first character of the supplied string to upper case.</p>
|
||
|
||
<div class="highlight highlight-php"><pre><span class="nx">S</span><span class="o">::</span><span class="na">create</span><span class="p">(</span><span class="s1">'σ test'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">)</span><span class="o">-></span><span class="na">upperCaseFirst</span><span class="p">();</span>
|
||
<span class="nx">S</span><span class="o">::</span><span class="na">upperCaseFirst</span><span class="p">(</span><span class="s1">'σ test'</span><span class="p">,</span> <span class="s1">'UTF-8'</span><span class="p">);</span> <span class="c1">// 'Σ test'</span>
|
||
</pre></div>
|
||
|
||
<h2>
|
||
<a name="links" class="anchor" href="#links"><span class="octicon octicon-link"></span></a>Links</h2>
|
||
|
||
<p>The following is a list of libraries that extend Stringy:</p>
|
||
|
||
<ul>
|
||
<li>
|
||
<a href="https://github.com/danielstjules/SliceableStringy">SliceableStringy</a>:
|
||
Python-like string slices in PHP</li>
|
||
</ul><h2>
|
||
<a name="tests" class="anchor" href="#tests"><span class="octicon octicon-link"></span></a>Tests</h2>
|
||
|
||
<p>From the project directory, tests can be ran using <code>phpunit</code></p>
|
||
|
||
<h2>
|
||
<a name="license" class="anchor" href="#license"><span class="octicon octicon-link"></span></a>License</h2>
|
||
|
||
<p>Released under the MIT License - see <code>LICENSE.txt</code> for details.</p>
|
||
</section>
|
||
<footer>
|
||
<p>This project is maintained by <a href="https://github.com/danielstjules">danielstjules</a></p>
|
||
<p><small>Hosted on GitHub Pages — Theme by <a href="https://github.com/orderedlist">orderedlist</a></small></p>
|
||
</footer>
|
||
</div>
|
||
<script src="javascripts/scale.fix.js"></script>
|
||
|
||
</body>
|
||
</html> |