PHPackages                             algo/kmp - 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. algo/kmp

ActiveLibrary

algo/kmp
========

KMP string search algorithm

912C

Since Apr 9Pushed 10y ago2 watchersCompare

[ Source](https://github.com/c9s/phpkmp)[ Packagist](https://packagist.org/packages/algo/kmp)[ RSS](/packages/algo-kmp/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

KMP string match algorithm
==========================

[](#kmp-string-match-algorithm)

[![Build Status](https://camo.githubusercontent.com/3ef4b8a126ec79e7841e8a9fcf7b1862474e9309af785b8326f80dc44d6f6c96/68747470733a2f2f7472617669732d63692e6f72672f6339732f7068706b6d702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/c9s/phpkmp)

Requirement
-----------

[](#requirement)

- PHP ^5.3

Install
-------

[](#install)

```
phpize
make
make install
```

Usage
-----

[](#usage)

### `kmp_search(string haystack, string needle)`

[](#kmp_searchstring-haystack-string-needle)

Return value: (`int`) This function returns -1 if `needle` is not found in `haystack`.

```
$pos = kmp_search("zjifeoabcabcjiefjie", "abcabc");
```

### `kmp_prefix(string needle)`

[](#kmp_prefixstring-needle)

Return value: (`resource`) This function returns a resource of pre-computed prefixes array. The returned resource can be reused when there are multiple haystacks to be searched.

```
$prefix = kmp_prefix("abcabc");
$pos = kmp_search_prefix("zjifeoabcabcjiefjie", $prefix);
```

References
----------

[](#references)

- KMP algorithm
- MP algorithm

License
-------

[](#license)

Released under MIT license

###  Health Score

22

—

LowBetter than 23% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/3cc34cde233b660869ff329ed8e20df611f75dfb61aab3e30889ac153d3e5e61?d=identicon)[c9s](/maintainers/c9s)

---

Top Contributors

[![c9s](https://avatars.githubusercontent.com/u/50894?v=4)](https://github.com/c9s "c9s (25 commits)")

### Embed Badge

![Health badge](/badges/algo-kmp/health.svg)

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

PHPackages © 2026

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