PHPackages                             matecat/whole-text-finder - 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. [Search &amp; Filtering](/categories/search)
4. /
5. matecat/whole-text-finder

ActiveLibrary[Search &amp; Filtering](/categories/search)

matecat/whole-text-finder
=========================

A simple whole text finder written in PHP

v2.0.1(2mo ago)014.1k↓25%MITPHPPHP &gt;=8.3

Since Aug 30Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/matecat/whole-text-finder)[ Packagist](https://packagist.org/packages/matecat/whole-text-finder)[ Docs](https://github.com/matecat/whole-text-finder)[ RSS](/packages/matecat-whole-text-finder/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (4)Versions (24)Used By (0)

WholeTextFinder
===============

[](#wholetextfinder)

![license](https://camo.githubusercontent.com/5952c468dfc63b8c097e85a813acd3590efd6da2b8ae615afce2394649887176/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6d6174656361742f77686f6c652d746578742d66696e6465722e737667)![Packagist](https://camo.githubusercontent.com/d49f038aff7b657e1d53a2cf699729f03b6ad6e61d1c5217b3cc0c56daea32b3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6174656361742f77686f6c652d746578742d66696e6465722e737667)[![Build Status](https://camo.githubusercontent.com/3b749cc8044637d89439dd48b2ec690342c8d552f05ba8b468628586af40ee8f/68747470733a2f2f6170702e7472617669732d63692e636f6d2f6d6174656361742f77686f6c652d746578742d66696e6465722e7376673f746f6b656e3d7142617a786b4877503138683345576e486a6a46266272616e63683d6d61696e)](https://app.travis-ci.com/matecat/whole-text-finder)[![Quality Gate Status](https://camo.githubusercontent.com/dedf14f324d0b7f7855c5490eb9a25ad118f77824d48b48681c126d47055487c/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d6d6174656361745f77686f6c652d746578742d66696e646572266d65747269633d616c6572745f737461747573)](https://sonarcloud.io/summary/new_code?id=matecat_whole-text-finder)[![Coverage](https://camo.githubusercontent.com/d84e0790cd0e53a6fd37fd956765a11f850739b495161f04f2fb491ddafa4484/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d6d6174656361745f77686f6c652d746578742d66696e646572266d65747269633d636f766572616765)](https://sonarcloud.io/summary/new_code?id=matecat_whole-text-finder)[![Reliability Rating](https://camo.githubusercontent.com/c282786b28d09e3eea3410a9fb00700ff10330ce844b2c70b58e8194931f0d81/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d6d6174656361745f77686f6c652d746578742d66696e646572266d65747269633d72656c696162696c6974795f726174696e67)](https://sonarcloud.io/summary/new_code?id=matecat_whole-text-finder)[![Maintainability Rating](https://camo.githubusercontent.com/2c62238efd44bdd67a489593c8f469e319cb3b5866566c5cf048ef8f63670b62/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d6d6174656361745f77686f6c652d746578742d66696e646572266d65747269633d7371616c655f726174696e67)](https://sonarcloud.io/summary/new_code?id=matecat_whole-text-finder)

**WholeTextFinder** is a simple whole text finder.

Basic Usage
-----------

[](#basic-usage)

Use the `find` method. Here is a basic search:

```
//..
use Finder\WholeTextFinder;

$haystack  = "PHP PHP is the #1 web scripting PHP language of choice.";
$needle = "php";

// 3 matches
$matches = WholeTextFinder::find($haystack, $needle);

// $matches is equals to:
//
// array(3) {
//    [0] =>
//  array(2) {
//            [0] =>
//    string(3) "PHP"
//            [1] =>
//    int(0)
//  }
//  [1] =>
//  array(2) {
//            [0] =>
//    string(3) "PHP"
//            [1] =>
//    int(4)
//  }
//  [2] =>
//  array(2) {
//            [0] =>
//    string(3) "PHP"
//            [1] =>
//    int(32)
//  }
// }
```

### Multi bytes strings

[](#multi-bytes-strings)

Please note that `WholeTextFinder::find` function is multi byte safe and returns the correct word positions in the original phrase. Take a look here:

```
//..
use Finder\WholeTextFinder;

$haystack  = "La casa è bella bella";
$needle = "bella";

$matches = WholeTextFinder::find($haystack, $needle, true, true, true);

// $matches is equals to:
// array (
//    0 =>
//        array (
//            0 => 'bella',
//            1 => 10,
//        ),
//    1 =>
//        array (
//            0 => 'bella',
//            1 => 16,
//        ),
//)
```

Find and Replace
----------------

[](#find-and-replace)

There is also available a `findAndReplace` method:

```
//..
use Finder\WholeTextFinder;

$haystack = 'Δύο παράγοντες καθόρισαν την αντίληψή μου για την Τενεσί Ουίλιαμς και τη σκηνική παρουσίαση των κειμένων: η Maria Britneva και η Annette Saddik, αφετέρου.';
$needle = 'και';
$replacement = 'test';

$matches = WholeTextFinder::findAndReplace($haystack, $needle, $replacement);

// $matches is equals to:
//
// array(2) {
//   ["replacement"]=>
//   string(252) "Δύο παράγοντες καθόρισαν την αντίληψή μου για την Τενεσί Ουίλιαμς test τη σκηνική παρουσίαση των κειμένων: η Maria Britneva test η Annette Saddik, αφετέρου."
//   ["occurrences"]=>
//   array(2) {
//     [0]=>
//     array(2) {
//       [0]=>
//       string(6) "και"
//       [1]=>
//       int(66)
//     }
//     [1]=>
//     array(2) {
//       [0]=>
//       string(6) "και"
//       [1]=>
//       int(123)
//     }
//   }
// }
//
```

This method will automatically **exclude** from replace HTML and some Matecat special tags, but allows to replace the inner content inside HTML tags.

So, for example:

```
//..
use Finder\WholeTextFinder;

// Example 1
$haystack = "Beauty -> 2 Anti-Akne Gesichtsreiniger Schlankmacher XXX";
$needle = 2;
$replacement = "test";

$matches = WholeTextFinder::findAndReplace($haystack, $needle, $replacement);

// $matches is equals to:
//
// array(2) {
//   ["replacement"]=>
//   string(252) "Beauty -> test Anti-Akne Gesichtsreiniger Schlankmacher XXX"
//   ["occurrences"]=>
//   array(1) {
//    [0]=>
//      array(2) {
//        [0]=>
//        string(1) "2"
//        [1]=>
//        int(10)
//     }
//   }
// }
//

// Example 2
$haystack = "Beauty -> 2 Anti-Akne Gesichtsreiniger Schlankmacher XXX";
$needle = 'XXX';
$replacement = "test";

$matches = WholeTextFinder::findAndReplace($haystack, $needle, $replacement);

// $matches is equals to:
//
// array(2) {
//   ["replacement"]=>
//   string(252) "Beauty -> 2 Anti-Akne Gesichtsreiniger Schlankmacher test"
//   ["occurrences"]=>
//   array(1) {
//    [0]=>
//      array(2) {
//        [0]=>
//        string(1) "test"
//        [1]=>
//        int(55)
//     }
//   }
// }
//
```

Search options
--------------

[](#search-options)

Some options are avaliable:

You can also specify four options:

- **$skipHtmlEntities** (`true` by default)
- **$exactMatch** (`false` by default)
- **$caseSensitive** (`false` by default)
- **$preserveNbsps** (`false` by default)

Here are some examples:

```
//..
use Finder\WholeTextFinder;

$haystack  = "PHP PHP is the #1 web scripting PHP language of choice.";

// 0 matches
$needle = "php";
$matches = WholeTextFinder::find($haystack, $needle, true, true, true);

// 1 match
$needle = "#1";
$matches = WholeTextFinder::find($haystack, $needle, true, true, true);

// 1 match, even if the haystack contains an invisible nbsp and the needle has an ordinary spacer
$haystackWithNbsp  = "Lawful basis for processing including basis of legitimate interest";
$needleWithoutNbsp = "Lawful basis for processing including basis of legitimate interest";
$matches = WholeTextFinder::find($haystackWithNbsp, $needleWithoutNbsp, true, true, true);

```

Support
-------

[](#support)

If you found an issue or had an idea please refer [to this section](https://github.com/mauretto78/whole-text-finder/issues).

Authors
-------

[](#authors)

- **Mauro Cassani** - [github](https://github.com/mauretto78)

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details

###  Health Score

55

—

FairBetter than 98% of packages

Maintenance83

Actively maintained with recent releases

Popularity25

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity83

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 92.6% 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 ~131 days

Recently: every ~432 days

Total

19

Last Release

88d ago

Major Versions

v1.0.16 → v2.0.02026-02-20

PHP version history (3 changes)v1.0.0PHP &gt;=5.5

v1.0.16PHP &gt;=7.4

v2.0.0PHP &gt;=8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/b9a5ee22f08424377759a39efc8bc6db4d0460db2afb97b8d6c950c14a9d5666?d=identicon)[MateCat-bot](/maintainers/MateCat-bot)

---

Top Contributors

[![mauretto78](https://avatars.githubusercontent.com/u/10035321?v=4)](https://github.com/mauretto78 "mauretto78 (50 commits)")[![Ostico](https://avatars.githubusercontent.com/u/8008416?v=4)](https://github.com/Ostico "Ostico (4 commits)")

---

Tags

phpsearchtext

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/matecat-whole-text-finder/health.svg)

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

###  Alternatives

[mmanos/laravel-search

A search package for Laravel 5.

36475.7k1](/packages/mmanos-laravel-search)[centamiv/vektor

A native PHP Vector Database implementation with strict binary storage and Zero-RAM overhead.

3418.5k2](/packages/centamiv-vektor)[omaressaouaf/query-builder-criteria

Define reusable query criteria for filtering, sorting, search, field selection, and includes in Laravel Eloquent models

282.4k](/packages/omaressaouaf-query-builder-criteria)[apicart/fql

Filter Query Language

1110.6k](/packages/apicart-fql)

PHPackages © 2026

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