PHPackages                             windwalker/string - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. windwalker/string

ActiveWindwalker-package[Framework](/categories/framework)

windwalker/string
=================

Windwalker String package

3.5.23(5y ago)1432.0k↓49.3%LGPL-2.0-or-laterPHPPHP &gt;=7.1.3

Since Oct 5Pushed 3y ago3 watchersCompare

[ Source](https://github.com/windwalker-io/string)[ Packagist](https://packagist.org/packages/windwalker/string)[ Docs](https://github.com/ventoviro/windwalker-string)[ RSS](/packages/windwalker-string/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (2)Versions (82)Used By (0)

Windwalker String
=================

[](#windwalker-string)

Windwalker String package provides UTF-8 string operation, it is a Joomla String fork but added more functions.

Installation via Composer
-------------------------

[](#installation-via-composer)

Add this to the require block in your `composer.json`.

```
{
    "require": {
        "windwalker/string": "~3.0"
    }
}
```

New Str Class
-------------

[](#new-str-class)

After 3.2, Windwalker has a new `Str` class and we will continue replace all old `StringHelper` will it in the future:

```
use Windwalker\String\Str;

string : Str::getChar($string, $pos, $encoding = null);
string : Str::between($string, $start, $end, $offset = 0, $encoding = null);
string : Str::collapseWhitespaces($string);
bool :   Str::contains($string, $search, $caseSensitive = true, $encoding = null);
bool :   Str::endsWith($string, $search, $caseSensitive = true, $encoding = null);
bool :   Str::startsWith($string, $target, $caseSensitive = true, $encoding = null);
string : Str::ensureLeft($string, $search, $encoding = null);
string : Str::ensureRight($string, $search, $encoding = null);
bool :   Str::hasLowerCase($string, $encoding = null);
bool :   Str::hasUpperCase($string, $encoding = null);
bool :   Str::match($pattern, $string, $option = 'msr', $encoding = null);
string : Str::insert($string, $insert, $position, $encoding = null);
bool :   Str::isLowerCase($string);
bool :   Str::isUpperCase($string);
string : Str::first($string, $length = 1, $encoding = null);
string : Str::last($string, $length = 1, $encoding = null);
string : Str::intersectLeft($string1, $string2, $encoding = null);
string : Str::intersectRight($string1, $string2, $encoding = null);
string : Str::intersect($string1, $string2, $encoding = null);
string : Str::pad($string, $length = 0, $substring = ' ', $encoding = null);;
string : Str::padLeft($string, $length = 0, $substring = ' ', $encoding = null);;
string : Str::padRight($string, $length = 0, $substring = ' ', $encoding = null);;
string : Str::removeChar($string, $offset, $length = null, $encoding = null);
string : Str::removeLeft($string, $search, $encoding = null);
string : Str::removeRight($string, $search, $encoding = null);
string : Str::slice($string, $start, $end = null, $encoding = null);
string : Str::substring($string, $start, $end = null, $encoding = null);
string : Str::surround($string, $substring = ['"', '"']);
string : Str::toggleCase($string, $encoding = null);
string : Str::truncate();;
string : Str::map($string, callable $callback, $encoding = null);
string : Str::filter($string, callable $callback, $encoding = null);
string : Str::reject($string, callable $callback, $encoding = null);
```

New StringObject
----------------

[](#new-stringobject)

`StringObject` is a class to help us manipulation string by OO way.

Create string object:

```
$str = str('Hello');

// OR

$str = new StringObject('Hello');
$str = StringObject::create('Hello');
```

### Usage

[](#usage)

```
$str[3]; // Get letter

// Iterator
foreach ($str as $letter)
{
    echo $letter
}

// Chaining modify, it is a immutable object, must reuturn self.
$str = $str->toUpperCase()
    ->trimLeft()
    ->truncate();

// to string
echo $str;
```

### Methods

[](#methods)

```
$str->count();
$str->getString();
$str->withString($string);
$str->toLowerCase();
$str->toUpperCase();
$str->length();
$str->chop($length = 1);
$str->replace($search, $replacement, &$count = null);
$str->compare($compare, $caseSensitive = true);
$str->reverse();
$str->substrReplace($replace, $start, $offset = null);
$str->trimLeft($charlist = null);
$str->trimRight($charlist = null);
$str->trim($charlist = null);
$str->upperCaseFirst();
$str->lowerCaseFirst();
$str->upperCaseWords();
$str->substrCount($search, $caseSensitive = true);
$str->indexOf($search);
$str->indexOfLast($search);
$str->explode($delimiter, $limit = null);
$str->apply(callable $callback);
$str->getChar(int $pos);
$str->between(string $start, string $end, int $offset = 0);
$str->collapseWhitespaces(string $string);
$str->contains(string $search, bool $caseSensitive = true);
$str->endsWith(string $search, bool $caseSensitive = true);
$str->startsWith(string $target, bool $caseSensitive = true);
$str->ensureLeft(string $search);
$str->ensureRight(string $search);
$str->hasLowerCase();
$str->hasUpperCase();
$str->match(string $pattern, string $option = 'msr');
$str->insert(string $insert, int $position);
$str->isLowerCase();
$str->isUpperCase();
$str->first(int $length = 1);
$str->last(int $length = 1);
$str->intersectLeft(string $string2);
$str->intersectRight(string $string2);
$str->intersect(string $string2);
$str->pad(int $length = 0, string $substring = ' ');
$str->padLeft(int $length = 0, string $substring = ' ');
$str->padRight(int $length = 0, string $substring = ' ');
$str->removeChar(int $offset, int $length = null);
$str->removeLeft(string $search);
$str->removeRight(string $search);
$str->slice(int $start, int $end = null);
$str->substring(int $start, int $end = null);
$str->surround($substring = ['"', '"']);
$str->toggleCase();
$str->truncate(int $length, string $suffix = '', bool $wordBreak = true);
$str->map(callable $callback);
$str->filter(callable $callback);
$str->reject(callable $callback);
```

Simple Template Engine
----------------------

[](#simple-template-engine)

Simple variable replace.

```
use Windwalker\String\SimpleTemplate;

$string = 'Hello my name is: {{ name }}~~~!!!';

SimpleTemplate::render($string, array('name' => 'Simon')); // Hello my name is Simon~~~!!!
```

Multi-level variable.

```
$string = 'Hello my name is: {{ user.name }} and ID is: {{ user.id }}~~~!!!';

$array = array(
    'user' => array(
        'name' => 'Simon',
        'id' => 123
    )
);

SimpleTemplate::render($string, $array); // Hello my name is Simon and ID is: 123~~~!!!
```

Custom Tags:

```
$string = 'Hello my name is: {$ name $}~~~!!!';

SimpleTemplate::render($string, array('name' => 'Simon'), array('{$', '$}'); // Hello my name is Simon~~~!!!
```

Utf8String
----------

[](#utf8string)

Utf8String is a wrap of `phputf8` library:

```
use Windwalker\String\Utf8String;

$string = '這是一個最美的小情歌';

Utf8String::substr($string, 0, 5); // '這是一個最'
Utf8String::strlen($string); // 10

// More methods
Utf8String::is_ascii($string);

Utf8String::strpos($str, $search, $offset = false);

Utf8String::strrpos($str, $search, $offset = 0);

Utf8String::strtolower($string);

Utf8String::strtoupper($string);

Utf8String::str_ireplace($search, $replace, $str, $count = null);

Utf8String::str_split($str, $split_len = 1);

Utf8String::strcasecmp($str1, $str2, $locale = false);

Utf8String::strcmp($str1, $str2, $locale = false);

Utf8String::strcspn($str, $mask, $start = null, $length = null);

Utf8String::stristr($str, $search);

Utf8String::strrev($string);

Utf8String::strspn($str, $mask, $start = null, $length = null);

Utf8String::substr_replace($str, $repl, $start, $length = null);

Utf8String::ltrim($str, $charlist = null);

Utf8String::rtrim($str, $charlist = null);

Utf8String::trim($str, $charlist = null);

Utf8String::ucfirst($str, $delimiter = null, $newDelimiter = null);

Utf8String::ucwords($string);

Utf8String::transcode($source, $from_encoding, $to_encoding); // Equals to iconv())

Utf8String::valid($string);

Utf8String::compliant($string);

Utf8String::unicode_to_utf8($string);

Utf8String::unicode_to_utf16($string);
```

StringHelper
------------

[](#stringhelper)

### Empty String Determine

[](#empty-string-determine)

isEmpty()

```
use Windwalker\String\StringHelper;

StringHelper::isEmpty('');      // true
StringHelper::isEmpty(0);       // false
StringHelper::isEmpty(array()); // true
StringHelper::isEmpty(null);    // true
```

isZero()

```
StringHelper::isZero(0);    // true
StringHelper::isZero('0');  // true
StringHelper::isZero('');   // false
StringHelper::isZero(null); // false
```

### Quote

[](#quote)

An useful method to quate a string.

```
// Default quote is `"`
StringHelper::quote('foo'); // "foo"

// Custom quotes
StringHelper::quote('foo', array('{{', '}}')); // {{foo}}

// Backquote
StringHelper::backquote('foo'); // `foo`
```

### More Methods

[](#more-methods)

increment()

```
StringHelper::increment('Title'); // Title (2)
StringHelper::increment('Title', StringHelper::INCREMENT_STYLE_DASH); // Title-2
```

at()

```
StringHelper::at('歡迎光臨', 2); // 光
```

collapseWhitespace()

```
StringHelper::collapseWhitespace('Welcome   to   Windwalker'); // 'Welcome to Windwalker'
```

endsWith()

```
StringHelper::endsWith('歡迎光臨', '光臨' [, $caseSensive = true]); // true
```

startsWith()

```
StringHelper::startsWith('歡迎光臨', '歡迎' [, $caseSensive = true]); // true
```

```
// Default callback is array_push
StringHelper::explode('.', 'foo.bar', 3); // array('foo', 'bar', null);

// Shift null
StringHelper::explode('.', 'foo.bar', 3, 'array_shift'); // array(null, 'foo', 'bar');

// Limit
StringHelper::explode('.', 'foo.bar.yoo', 2); // array('foo', 'bar.yoo');

// Useful to use list()

list($foo, $bar, $yoo) = StringHelper::explode('.', 'foo.bar', 3);
```

StringInflector
---------------

[](#stringinflector)

```
use Windwalker\String\StringInflector;

$inflector = StringInflector::getInstance();
$string = 'category';

if ($inflector->isSingular($string))
{
    $string = $inflector->toPular(); // categories
}

if ($inflector->isPlural($string))
{
    $string = $inflector->toSingular(); // category
}
```

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity36

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 96.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~39 days

Recently: every ~280 days

Total

80

Last Release

1216d ago

Major Versions

2.1.9 → 3.0-beta2016-07-04

PHP version history (3 changes)2.0.0-beta1PHP &gt;=5.3.10

3.2PHP &gt;=5.5.9

3.5PHP &gt;=7.1.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1639206?v=4)[Simon Asika](/maintainers/asika32764)[@asika32764](https://github.com/asika32764)

---

Top Contributors

[![asika32764](https://avatars.githubusercontent.com/u/1639206?v=4)](https://github.com/asika32764 "asika32764 (87 commits)")[![megamount](https://avatars.githubusercontent.com/u/17608213?v=4)](https://github.com/megamount "megamount (3 commits)")

---

Tags

phpstringstring-classstring-manipulationframeworkstringwindwalker

### Embed Badge

![Health badge](/badges/windwalker-string/health.svg)

```
[![Health](https://phpackages.com/badges/windwalker-string/health.svg)](https://phpackages.com/packages/windwalker-string)
```

###  Alternatives

[windwalker/renderer

Windwalker Renderer package

855.0M28](/packages/windwalker-renderer)[windwalker/crypt

Windwalker Crypt package

1295.1k10](/packages/windwalker-crypt)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
