PHPackages                             mathsgod/langchain-text-splitter - 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. mathsgod/langchain-text-splitter

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

mathsgod/langchain-text-splitter
================================

A PHP library to split text into sentences and words.

1.0.0(2y ago)23.6k↓60.6%MITPHPPHP &gt;=8.0.0CI passing

Since Feb 27Pushed 3w ago1 watchersCompare

[ Source](https://github.com/mathsgod/langchain-text-splitter-php)[ Packagist](https://packagist.org/packages/mathsgod/langchain-text-splitter)[ RSS](/packages/mathsgod-langchain-text-splitter/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

langchain-text-splitter
=======================

[](#langchain-text-splitter)

[![Tests](https://github.com/mathsgod/langchain-text-splitter-php/actions/workflows/tests.yml/badge.svg)](https://github.com/mathsgod/langchain-text-splitter-php/actions/workflows/tests.yml)[![Latest Stable Version](https://camo.githubusercontent.com/990da3f591adb115dde4819ad6f46293bff8edf65f981389d1f5fd6eb9595386/68747470733a2f2f706f7365722e707567782e6f72672f6d61746873676f642f6c616e67636861696e2d746578742d73706c69747465722f76)](https://packagist.org/packages/mathsgod/langchain-text-splitter)[![License](https://camo.githubusercontent.com/b95f2cf01675a755d7c74f8d241dadb2e1d14dd7fa3f027004880f3591241c42/68747470733a2f2f706f7365722e707567782e6f72672f6d61746873676f642f6c616e67636861696e2d746578742d73706c69747465722f6c6963656e7365)](https://packagist.org/packages/mathsgod/langchain-text-splitter)

A simple text splitter that splits text into chunks of a given size with a given overlap.

This library is based on

Includes multi language support.

Requirements
------------

[](#requirements)

- PHP &gt;= 8.1
- ext-mbstring

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

[](#installation)

```
composer require mathsgod/langchain-text-splitter
```

Example
-------

[](#example)

```
use Langchain\TextSplitter\RecursiveCharacterTextSplitter;

require_once __DIR__ . '/vendor/autoload.php';

$ts = new RecursiveCharacterTextSplitter([
    "chunk_size" => 10,
    "chunk_overlap" => 2
]);

$text = "財政司長陳茂波明日公布新一份財政預算案，焦點之一是會否全面取消樓市逆周期措施。瑞銀發報告認為，在財赤及樓市疲軟下，預料港府會就樓市全面「撤辣」，但按2019年及去年的經驗，相信隨之而來的利好情緒只會維持4至16周，並續料今年樓價會下挫，最新預測會跌5%至10%，而早前的估計是跌少於10%。";

$chunks = $ts->splitText($text);

print_r($chunks);
/*
Array
(
    [0] => 財政司長陳茂波明日公
    [1] => 日公布新一份財政預算
    [2] => 預算案，焦點之一是會
    [3] => 是會否全面取消樓市逆
    [4] => 市逆周期措施。瑞銀發
    [5] => 銀發報告認為，在財赤
    [6] => 財赤及樓市疲軟下，預
    [7] => ，預料港府會就樓市全
    [8] => 市全面「撤辣」，但按
    [9] => 但按2019年及去年
    [10] => 去年的經驗，相信隨之
    [11] => 隨之而來的利好情緒只
    [12] => 緒只會維持4至16周
    [13] => 6周，並續料今年樓價
    [14] => 樓價會下挫，最新預測
    [15] => 預測會跌5%至10%
    [16] => 0%，而早前的估計是
    [17] => 計是跌少於10%。
)
*/
```

Splitters
---------

[](#splitters)

### `RecursiveCharacterTextSplitter`

[](#recursivecharactertextsplitter)

Recursively splits text by trying a list of separators (`["\n\n", "\n", " ", ""]` by default) until each piece fits within `chunk_size`. Suitable for general text.

```
$ts = new RecursiveCharacterTextSplitter([
    "chunk_size" => 500,
    "chunk_overlap" => 50,
    "separators" => ["\n\n", "\n", " ", ""], // optional
]);
```

### `CharacterTextSplitter`

[](#charactertextsplitter)

Splits text by a single configurable separator (`"\n\n"` by default) and merges the pieces into chunks of at most `chunk_size` characters.

```
$ts = new CharacterTextSplitter([
    "chunk_size" => 500,
    "chunk_overlap" => 50,
    "separator" => "\n\n", // optional
]);
```

Running Tests
-------------

[](#running-tests)

```
composer install
vendor/bin/phpunit
```

Tests run on PHP 8.1 through 8.5 via GitHub Actions.

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance62

Regular maintenance activity

Popularity25

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

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

858d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/18732337?v=4)[Raymond](/maintainers/mathsgod)[@mathsgod](https://github.com/mathsgod)

---

Top Contributors

[![mathsgod](https://avatars.githubusercontent.com/u/18732337?v=4)](https://github.com/mathsgod "mathsgod (9 commits)")

### Embed Badge

![Health badge](/badges/mathsgod-langchain-text-splitter/health.svg)

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

###  Alternatives

[laravel-arcanist/inertia-response-renderer

Inertia response renderer for Arcanist

132.2k](/packages/laravel-arcanist-inertia-response-renderer)

PHPackages © 2026

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