PHPackages                             originphp/text - 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. originphp/text

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

originphp/text
==============

OriginPHP Text

2.1.0(5y ago)15491MITPHPPHP &gt;=7.3.0CI failing

Since Oct 12Pushed 5y ago1 watchersCompare

[ Source](https://github.com/originphp/text)[ Packagist](https://packagist.org/packages/originphp/text)[ Docs](https://www.originphp.com)[ RSS](/packages/originphp-text/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (2)Versions (6)Used By (1)

Text
====

[](#text)

[![license](https://camo.githubusercontent.com/6fdb99389fe9d9e8a5c197002a191ace7c8b12a2020c0fa5756cf17aa08a4966/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874477265656e2e737667)](https://camo.githubusercontent.com/6fdb99389fe9d9e8a5c197002a191ace7c8b12a2020c0fa5756cf17aa08a4966/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874477265656e2e737667)[![build](https://github.com/originphp/text/workflows/CI/badge.svg)](https://github.com/originphp/text/actions)[![coverage](https://camo.githubusercontent.com/a0a560ee250c410cd3b25eb8d8734b008220fcf207339d0b5ff8322d9860afd3/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6f726967696e7068702f746578742f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/originphp/text?branch=master)

The Text utility has a number of methods to help when working with strings.

Installation
------------

[](#installation)

To install this package

```
$ composer require originphp/text

```

Converting Strings to Ascii
---------------------------

[](#converting-strings-to-ascii)

To convert a string into Ascii (Transliterate)

```
$ascii = Text::toAscii('Ragnarr Loðbrók'); // Ragnarr Lodbrok
```

Creating a Slug
---------------

[](#creating-a-slug)

To create a URL safe slug. The string will be converted to ASCII then any unkown characters will be replaced with the separator.

```
$slug = Text::slug('Who is Ragnarr Loðbrók?'); // who-is-ragnarr-lodbrok
```

Contains
--------

[](#contains)

To check if a string contains a substring.

```
$result = Text::contains('foo','What is foo bar'); // true
```

Getting parts of strings
------------------------

[](#getting-parts-of-strings)

When you need to get part of a string before or after a substring

```
$result = Text::left('foo','What is foo bar'); // 'What is '
$result = Text::right('foo','What is foo bar'); //' bar'
```

Checking the start and end of a string
--------------------------------------

[](#checking-the-start-and-end-of-a-string)

```
$bool = Text::startsWith('What','What is foo bar'); // true
$bool = Text::endsWith('bar','What is foo bar'); // true
```

Replace
-------

[](#replace)

To replace a substring with another string

```
$result = Text::replace('foo','***','What is foo bar'); // 'What is *** bar'
$result = Text::replace('foo','***','What is FOO bar',['insensitive'=>true]); // 'What is *** bar'
```

Insert
------

[](#insert)

To insert values into a string using placeholders (string interpolation)

```
$string = Text::insert('Record {id} has been updated',[
    'id'=>1234568
]); // Record 1234568 has been updated
```

Another example:

```
$letter = file_get_contents('/directory/some-file');
$string = Text::insert($letter,[
    'salutation' => 'Mr.',
    'first_name' => 'Tony',
    'last_name' => 'Robbins',
    'address_1' => '100 Santa Monica Road',
]);
```

You can also change the place holders

```
$string = Text::insert('Record :id has been updated',[
    'id'=>1234568,'before'=>':','after'=>''
    ]); // Record 1234568 has been updated
```

Tokenize
--------

[](#tokenize)

For quick and easy parsing of strings, the Tokenize method makes things simple. By default `tokenize` splits strings using a comma `,` and quotation mark `"` as an enclosure.

```
$string = '2019-07-10 13:30:00 192.168.1.22 "GET /users/login HTTP/1.0" 200 1024';
$result = Text::tokenize($string,['separator'=>' ']);

/*
// Will give you this
[
    '2019-07-10',
    '13:30:00',
    '192.168.1.22',
    'GET /users/login HTTP/1.0',
    '200',
    '1024'
];
*/
```

You can also supply keys instead which will be mapped.

```
$string = '2019-07-10 13:30:00 192.168.1.22 "GET /users/login HTTP/1.0" 200 1024';
$result = Text::tokenize($string,[
    'separator'=>' ',
    'keys'=>['date','time','ip','request','code','bytes']
]);

/*
// Will give you this
[
    'date'=>'2019-07-10',
    'time'=>'13:30:00',
    'ip' => '192.168.1.22',
    'request' =>'GET /users/login HTTP/1.0',
    'code'=>'200',
    'bytes'=>'1024'
];
*/
```

Truncate
--------

[](#truncate)

To truncate a string if it is longer than a specific length. The default length is 30.

```
$truncated = Text::truncate($string,['length'=>50,'end'=>'... truncated']);
```

Word Wrap
---------

[](#word-wrap)

To wordwrap a string

```
$wrapped = Text::wordWrap($string); // default is 80
$wrapped = Text::wordWrap($string,['width'=>50]);
```

Other
-----

[](#other)

Other handy string functions (through `mb_string`)

```
$lowerCase = Text::toLower($string);
$uppserCase = Text::toUpper($string);
$int = Text::length($string);
```

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity57

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

Every ~116 days

Total

5

Last Release

1989d ago

Major Versions

1.0.2 → 2.0.02021-01-04

PHP version history (3 changes)1.0.0PHP ^7.2.0

1.0.2PHP &gt;=7.2.0

2.0.0PHP &gt;=7.3.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/7e8a821333d9c7b7bc2ad3d164d142f65cd3912dea78033d31f76b0f19ba8a0c?d=identicon)[originphp](/maintainers/originphp)

---

Top Contributors

[![jamielsharief](https://avatars.githubusercontent.com/u/20553479?v=4)](https://github.com/jamielsharief "jamielsharief (16 commits)")

---

Tags

stringtextmergeoriginPHPtokenzie

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/originphp-text/health.svg)

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

###  Alternatives

[nette/utils

🛠 Nette Utils: lightweight utilities for string &amp; array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.

2.1k430.4M1.7k](/packages/nette-utils)[opis/string

Multibyte strings as objects

7626.6M8](/packages/opis-string)[lolli42/finediff

PHP implementation of a Fine granularity Diff engine

139.8M9](/packages/lolli42-finediff)[d4h/finediff

PHP implementation of a Fine granularity Diff engine

151.5M1](/packages/d4h-finediff)[phootwork/lang

Missing PHP language constructs

1228.2M8](/packages/phootwork-lang)[edgaras/strsim

Collection of string similarity and distance algorithms in PHP including Levenshtein, Damerau-Levenshtein, Jaro-Winkler, and more

2857.3k4](/packages/edgaras-strsim)

PHPackages © 2026

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