PHPackages                             conkal/ztring - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. conkal/ztring

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

conkal/ztring
=============

A string manipulation library

v1.0.0(4y ago)06MITPHPPHP &gt;=5.6.0

Since Jul 8Pushed 4y ago1 watchersCompare

[ Source](https://github.com/cengizonkal/ztring)[ Packagist](https://packagist.org/packages/conkal/ztring)[ RSS](/packages/conkal-ztring/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

ztring
======

[](#ztring)

[![Latest Stable Version](https://camo.githubusercontent.com/2fa9a6d625703f92dbd63074a7cbe53937e603919d8c8846a717734c8aa8345d/68747470733a2f2f706f7365722e707567782e6f72672f636f6e6b616c2f7a7472696e672f762f737461626c65)](https://packagist.org/packages/conkal/ztring)[![License](https://camo.githubusercontent.com/4d8ca8ddfceeff74f4a81c50b4d3cfa22850cf118197541ed1e18312c52d5dc8/68747470733a2f2f706f7365722e707567782e6f72672f636f6e6b616c2f7a7472696e672f6c6963656e7365)](https://packagist.org/packages/conkal/ztring)[![Total Downloads](https://camo.githubusercontent.com/d0deae8aef35bb29f2bcccb67045a5d070f6625682d278f38aa09e47d2f09c74/68747470733a2f2f706f7365722e707567782e6f72672f636f6e6b616c2f7a7472696e672f646f776e6c6f616473)](https://packagist.org/packages/conkal/ztring)[![Build](https://github.com/cengizonkal/ztring/workflows/Build/badge.svg)](https://github.com/cengizonkal/ztring/workflows/Build/badge.svg)

A PHP string manipulation library.

- [Installation](#installation)
- [OO and Chaining](#oo-and-chaining)
- [Class methods](#class-methods)

  [append](#append) [prepend](#prepend) [camelcase](#camelcase) [count](#count)   [at](#at) [chars](#chars) [collapseWhitespace](#collapsewhitespace) [endsWith](#endswith)   [ensureLeft](#ensureleft) [ensureRight](#ensureright) [firstChar](#firstchar) [firstXChars](#firstxchars)   [lastChar](#lastchar) [lastXChars](#lastxchars) [length](#length) [lowerCaseFirst](#lowercasefirst)   [prepend](#prepend) [replace](#replace) [reverse](#reverse) [random](#random)   [slug](#slug) [startsWith](#startswith) [substr](#substr) [swapCase](#swapcase)   [removeWhiteSpace](#removewhitespace) [lowerCase](#lowercase) [toBoolean](#toboolean) [ascii](#ascii)   [trim](#trim) [words](#words) [sanitize](#sanitize) [acronym](#acronym)   [number](#number) Installation
------------

[](#installation)

```
composer require conkal/ztring

```

```
use Conkal\ztring;
```

OO and Chaining
---------------

[](#oo-and-chaining)

The library offers OO method chaining, as seen below:

```
use Conkal\ztring;
echo ztring('this is test')->collapseWhitespace()->swapCase(); // THIS IS TEST
```

`Conkal\ztring` has a \_\_toString() method, which returns the current string when the object is used in a string context, ie: `(string) ztring::create('foo')  // 'foo'`

Implemented Interfaces
----------------------

[](#implemented-interfaces)

`Conkal\ztring` implements the `IteratorAggregate` interface, meaning that `foreach` can be used with an instance of the class:

```
$string = \Conkal\ztring::create('test');
foreach ($string as $char) {
    echo $char;
}
// 'test'
```

It implements the `Countable` interface, enabling the use of `count()` to retrieve the number of characters in the string:

```
$string = \Conkal\ztring::create('test');
count($string);  // 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 `Conkal\ztring` 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`.

```
$string = \Conkal\ztring::create('test');
echo $string[1];     // 't'
```

Class methods
-------------

[](#class-methods)

##### create(string $str)

[](#createstring-str)

Creates a ztring object and assigns string property. $str is cast to a string prior to assignment.

```
$string = \Conkal\ztring::create('test'); // 'test'
```

Instance Methods
----------------

[](#instance-methods)

##### append(string $string)

[](#appendstring-string)

Returns a new string with $string appended.

```
ztring('This is a ')->append('test.'); // This is a test.
```

##### at(int $index)

[](#atint-index)

Returns the character at $index, with indexes starting at 0.

```
ztring('This is a test')->at(0); // 'T'
ztring('This is a test')->at(1); // 'h'
ztring('This is a test')->at(-1); // 't'
```

##### camelcase()

[](#camelcase)

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.

```
ztring('Camel-Case')->camelcase(); // 'camelCase'
```

##### chars()

[](#chars)

Returns an array consisting of the characters in the string.

```
ztring('test')->chars(); // ['t','e','s','t']
```

##### collapseWhitespace()

[](#collapsewhitespace)

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.

```
ztring('This   is a               test')->collapseWhitespace(); // 'This is a test'
```

##### endsWith(string $substring \[, boolean $caseSensitive = true \])

[](#endswithstring-substring--boolean-casesensitive--true-)

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.

```
ztring('this is a test')->endsWith('test'); // true
```

##### ensureLeft(string $substring)

[](#ensureleftstring-substring)

Ensures that the string begins with $substring. If it doesn't, it's prepended.

```
ztring('foobar')->ensureLeft('http://'); // 'http://foobar'
```

##### ensureRight(string $substring)

[](#ensurerightstring-substring)

Ensures that the string ends with $substring. If it doesn't, it's appended.

```
ztring('foobar')->ensureRight('.com'); // 'foobar.com'
```

##### firstChar()

[](#firstchar)

Returns the first $n characters of the string.

```
ztring('test')->firstChar(); // 't'
```

##### firstXChars()

[](#firstxchars)

Returns the first $n characters of the string.

```
ztring('test')->first3Chars(); // 'tes'
```

##### lastChar()

[](#lastchar)

Returns the last $n characters of the string.

```
ztring('test')->lastChar(); // 't'
```

##### lastXChars()

[](#lastxchars)

Returns the last $n characters of the string.

```
ztring('test')->last3Chars(); // 'est'
```

##### length()

[](#length)

Returns the length of the string. An alias for PHP's mb\_strlen() function.

```
ztring('fòôbàř')->length(); // 6
```

##### lowerCaseFirst()

[](#lowercasefirst)

Converts the first character of the supplied string to lower case.

```
ztring('Test')->lowerCaseFirst(); // 'test'
```

##### prepend(string $string)

[](#prependstring-string)

Returns a new string starting with $string.

```
ztring('bàř')->prepend('fòô'); // 'fòôbàř'
```

##### removeLeft(string $substring)

[](#removeleftstring-substring)

Returns a new string with the prefix $substring removed, if present.

##### replace(string $search, string $replacement)

[](#replacestring-search-string-replacement)

Replaces all occurrences of $search in $str by $replacement.

```
ztring('This is test.')->replace('This ', 'These '); // 'These is test.'
```

##### reverse()

[](#reverse)

Returns a reversed string. A multibyte version of strrev().

```
ztring('fòôbàř')->reverse(); // 'řàbôòf'
```

##### random()

[](#random)

Create a random string

```
\Conkal\ztring::random();
```

##### slug( \[string $separator = '-'\])

[](#slug-string-separator---)

```
ztring('This is a testğüşçö')->slug(); // 'this-is-a-test'
```

##### startsWith(string $substring \[, boolean $caseSensitive = true \])

[](#startswithstring-substring--boolean-casesensitive--true-)

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.

```
ztring('This is a test')->startsWith('This', false); // true
```

##### substr(int $start \[, int $length \])

[](#substrint-start--int-length-)

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.

```
ztring('This is a test')->substr(0, 4); // 'This'
```

##### swapCase()

[](#swapcase)

Returns a case swapped version of the string.

```
ztring('Test')->swapCase(); // 'tEST'
```

##### titleCase()

[](#titlecase)

Returns a trimmed string with the first letter of each word capitalized.

```
ztring('this is a test')->titleCase();
// 'This Is A Test'
```

##### ascii($languageSpecific)

[](#asciilanguagespecific)

Returns an ASCII version of the string.

```
  $languageSpecific = [
            'ğ' => 'g',
            'ü' => 'u',
            'ı' => 'i',
            'ş' => 's',
            'ç' => 'c',
            'ö' => 'o',
            'Ğ' => 'G',
            'Ü' => 'U',
            'Ş' => 'S',
            'Ö' => 'O',
            'Ç' => 'C',
            'İ' => 'I',
        ];
ztring('türkçe')->ascii($languageSpecific); // 'turkce'
```

##### toBoolean()

[](#toboolean)

Returns a boolean representation of the given logical string value. For example, 'true', '1', 'on' and 'yes' will return true. 'false', '0', 'off', and 'no' will return false. In all instances, case is ignored.

```
ztring('OFF')->toBoolean(); // false
```

##### toLowerCase()

[](#tolowercase)

Converts all characters in the string to lowercase. An alias for PHP's mb\_strtolower().

```
ztring('THIS')->lowerCase(); // 'this'
```

##### toTitleCase()

[](#totitlecase)

Converts the first character of each word in the string to uppercase.

```
ztring('this is a test')->titleCase(); // 'Fòô Bàř'
```

##### uppercase()

[](#uppercase)

Converts all characters in the string to uppercase. An alias for PHP's mb\_strtoupper().

```
ztring('test')->uppercase(); // 'TEST'
```

##### trim(\[, string $chars\])

[](#trim-string-chars)

Returns a string with whitespace removed from the start and end of the string. Supports the removal of unicode whitespace. Accepts an optional string of characters to strip instead of the defaults.

```
ztring('  test  ')->trim(); // 'test'
```

##### upperCaseFirst()

[](#uppercasefirst)

Converts the first character of the supplied string to upper case.

```
ztring('this is a test')->upperCaseFirst(); // 'This is a test'
```

##### words()

[](#words)

Returns words as array

```
ztring('this is a test')->words(); // ['This', 'is', 'a', 'test']
```

##### sanitize()

[](#sanitize)

Removes all special characters

```
ztring('this is a test?--*üğişçö')->sanitize(); // 'this is a test'
```

##### acronym()

[](#acronym)

Creates an acronym

```
ztring('This is a test')->acronym(); // 'TIAT'
ztring('This is a test')->acronym('.'); // 'T.I.A.T.'
```

##### number()

[](#number)

return only digits between 0-9

```
ztring('1---*?=)(2hjkghkj,iüğ\ş3/*-')->number(); //123
```

Tests
-----

[](#tests)

From the project directory, tests can be ran using `phpunit`

License
-------

[](#license)

Released under the MIT License - see `LICENSE.txt` for details.

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

1766d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/cb4b44348f594e1fc43ce6f40d31092b71c288d5897b4a992012e4efa37fca6b?d=identicon)[Cengiz Önkal](/maintainers/Cengiz%20%C3%96nkal)

---

Top Contributors

[![cengizonkal](https://avatars.githubusercontent.com/u/3024926?v=4)](https://github.com/cengizonkal "cengizonkal (3 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/conkal-ztring/health.svg)

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

PHPackages © 2026

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