PHPackages                             floor9design/search-string-parser - 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. floor9design/search-string-parser

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

floor9design/search-string-parser
=================================

A php based parser class for use in search logic.

0.9.1(11y ago)31471GNU GENERALPHPPHP &gt;=5.3.0

Since Jan 5Pushed 9y ago3 watchersCompare

[ Source](https://github.com/elb98rm/search-string-parser)[ Packagist](https://packagist.org/packages/floor9design/search-string-parser)[ Docs](https://github.com/elb98rm/:search-string-parser)[ RSS](/packages/floor9design-search-string-parser/feed)WikiDiscussions master Synced 1mo ago

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

search-string-parser
====================

[](#search-string-parser)

[![Latest Version](https://camo.githubusercontent.com/53225d1aae6543dea34cd02c0fca7274ad9c31b5d34c4607c203a63ab7bf1161/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f656c623938726d2f7365617263682d737472696e672d7061727365722e7376673f7374796c653d706c6173746963)](https://github.com/elb98rm/search-string-parser/releases)[![Software License](https://camo.githubusercontent.com/10955426da15c7ed27f262e19d2eddeb65055494880cc858e8fc0792d5e15d1c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d706c6173746963)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/1cf6ee517ae47dc44637564966592928a0546926028bca1654604bfe7d0b1a53/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7365617263682d737472696e672d7061727365722f6d61737465722e7376673f7374796c653d706c6173746963)](https://travis-ci.org/elb98rm/search-string-parser)[![Coverage Status](https://camo.githubusercontent.com/14b82f80cc367acdf9df45b7ce67ec92688fdd613ac5a7b702c3f246a65392e8/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f7365617263682d737472696e672d7061727365722f7365617263682d737472696e672d7061727365722e7376673f7374796c653d706c6173746963)](https://scrutinizer-ci.com/g/thephpleague/search-string-parser/code-structure)[![Quality Score](https://camo.githubusercontent.com/7ae75c9feee62638f26002034bc7ba99f65649eece01a1b4292d636d1267dfcb/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7365617263682d737472696e672d7061727365722f7365617263682d737472696e672d7061727365722e7376673f7374796c653d706c6173746963)](https://scrutinizer-ci.com/g/thephpleague/search-string-parser)[![Total Downloads](https://camo.githubusercontent.com/9581a956d4fdeca59b2342586c906d5dfbdc8e0bd0ce762234335f04de06629c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c65616775652f7365617263682d737472696e672d7061727365722e7376673f7374796c653d706c6173746963)](https://packagist.org/packages/league/search-string-parser)

A php based parser that will turn a string into an array of search terms for usage in search logic. \*\* This software is currently in a beta release: 0.9.3 \*\*

It is to be released on [packagist.org](https://packagist.org/).

Items left to look at:

- Finish ParserEn implementation - currently under development
- Testing has been restored to 100% on files not being redeveloped
- Documentation to be expanded to be more "ELI5"

This should be PSR-2, PSR-4 compliant, but as it's a beta there may be some problems.

Install
-------

[](#install)

Via Composer

```
composer require league/search-string-parser
```

Usage
-----

[](#usage)

There are different engines Parsers available. You can easily choose which you want to use. Currently in this Beta version ParserSimple and ParserEn are included.

Instantiate the wrapper using an object of the type of search you want:

```
// Instantiate
$ssp = new SearchStringParser(new ParserSimple);
// run a search:
$string = 'some search terms "including literals enclosed in quotes"';
$array = $ssp->parse($string);
```

This will give you the following results set:

```
array(
    0 => 'including literals enclosed in quotes',
    1 => 'some',
    2 => 'search',
    3 => 'terms'
);
```

Spaces are treated as "OR", with literals meaning "This string exactly"

- hello world =&gt; hello OR world
- "hello world" =&gt; hello AND \[ space \] AND world

Your search string can include a combination of the following items:

- strings - eg: hello world
- literal string - eg: "hello world"
- int - eg: 1
- float - eg: -14.54
- array
- multi-dimensional array

These are all parsed internally to form an array ready for you to use as you see fit!

Here is a more complex example:

```
// Instantiate
$ssp = new SearchStringParser(new ParserSimple);
// run a search:
$complex = array(
            0 => 'hello world',
            1 => 'foo',
            2 => 'bar "literal string"',
            3 => 3,
            4 => -19.27
        );
$array = $ssp->parse($complex);
```

This gives the following result:

```
array(
    0 => 'literal string',
    1 => 'hello',
    2 => 'world',
    3 => 'foo',
    4 => 'bar',
    5 => '3',
    6 => '-19.27'
);
```

You can also change the delimiter:

```
// Instantiate
$ssp = new SearchStringParser(new ParserSimple);
// run a search:
$string = 'some "search terms" Pincluding literals enclosed in another letterP';
$array = $ssp->parse($string);
```

This will give you the following results set:

```
array(
    0 => 'including literals enclosed in another letter',
    1 => 'some',
    2 => '"search',
    3 => 'terms"'
);
```

A practical use case; In Zend Framework you may need to set up a set of search terms:

```
// we are in the middle of the code, and the object has already been instantiated as above:
 $string = 'some input text "including literals enclosed in quotes"';
$array = $ssp->parse($string);
 // ... I'll now skip to the relevant part of zend - I assume you can write a query:
 foreach($array as $keyword) {
   $select->orWhere('data_table LIKE ?', "%$keyword%")
}
```

Obviously, this is just a push in the right direction, though similar things can be done in almost all frameworks (as well as in raw SQL).

Testing
-------

[](#testing)

Ensure that you have run composer scripts to generate vendor/autoload.php Run the following in command line at the project root:

```
$ phpunit --bootstrap vendor/autoload.php tests/
```

Credits
-------

[](#credits)

- [Rick morice](https://github.com/elb98rm)

License
-------

[](#license)

GNU GENERAL PUBLIC LICENSE. Please see [License File](LICENSE.md) for more information.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity50

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 ~0 days

Total

2

Last Release

4142d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ca241b0576f1570f1de86d5cb18429e6a662cc165c1e798d321754a549d65a27?d=identicon)[elb98rm](/maintainers/elb98rm)

---

Top Contributors

[![elb98rm](https://avatars.githubusercontent.com/u/2630101?v=4)](https://github.com/elb98rm "elb98rm (37 commits)")

---

Tags

searchparserpackageleague

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/floor9design-search-string-parser/health.svg)

```
[![Health](https://phpackages.com/badges/floor9design-search-string-parser/health.svg)](https://phpackages.com/packages/floor9design-search-string-parser)
```

###  Alternatives

[netgen/query-translator

Query Translator is a search query translator with AST representation

2042.0M6](/packages/netgen-query-translator)[smile/module-elasticsuite-cms-search

Smile Elasticsuite - Cms Pages Search Module for Smile Elasticsuite.

25916.7k1](/packages/smile-module-elasticsuite-cms-search)[hollodotme/treemdown

A PHP class for browsing markdown files with HTML rendering, syntax highlighting and search

1440.9k3](/packages/hollodotme-treemdown)[apicart/fql

Filter Query Language

1110.6k](/packages/apicart-fql)[dialekt/dialekt

A boolean expression DSL.

173.7k](/packages/dialekt-dialekt)[bvdputte/kirby-bettersearch

A search plugin for Kirby (v3+ that searches for full word combinations rather than just individual words.

233.5k](/packages/bvdputte-kirby-bettersearch)

PHPackages © 2026

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