PHPackages                             hugsbrugs/php-keywords - 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. hugsbrugs/php-keywords

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

hugsbrugs/php-keywords
======================

PHP Text Utilities

11081[1 issues](https://github.com/hugsbrugs/php-keywords/issues)HTML

Since Sep 18Pushed 2y ago1 watchersCompare

[ Source](https://github.com/hugsbrugs/php-keywords)[ Packagist](https://packagist.org/packages/hugsbrugs/php-keywords)[ RSS](/packages/hugsbrugs-php-keywords/feed)WikiDiscussions master Synced 5d ago

READMEChangelogDependenciesVersions (1)Used By (0)

php-keywords
============

[](#php-keywords)

Test my free and online [Keyword Density Checker](https://hugo.maugey.fr/tools/keyword-density-checker)

This library provides PHP functions to extract keywords from HTML and text. Read [PHP DOC](https://hugsbrugs.github.io/php-keywords)

[![Build Status](https://camo.githubusercontent.com/d3cb30f62edd96d28c909a949bd55ba7e1492e9262a60438bca9a19b830f07df/68747470733a2f2f7472617669732d63692e6f72672f6875677362727567732f7068702d6b6579776f7264732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/hugsbrugs/php-keywords)[![Coverage Status](https://camo.githubusercontent.com/fbb4dcabeecbec130316d2757ac4a10cb6cb789e04212b00c3b33d416e33f4d3/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6875677362727567732f7068702d6b6579776f7264732f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/hugsbrugs/php-keywords?branch=master)

Install
-------

[](#install)

Install package with composer

```
composer require hugsbrugs/php-keywords

```

In your PHP code, load librairy

```
require_once __DIR__ . '/vendor/autoload.php';
use Hug\Keywords\Keywords as Keywords;
```

Usage
-----

[](#usage)

If you have HTML as input, first extract text from HTML (it also returns Title and meta description)

```
$text = Keywords::get_text_from_html($html);
```

Then call the Keyword class with text as only required parameter. In this case the library [patrickschur/language-detection](https://github.com/patrickschur/language-detection) will be used to automatically detect language.

```
$Keywords = new Keywords($text);
$kws = $Keywords->keywords;
```

If you know which language is used in your text, then pass parameter lang as second argument. It will allow to load stop words list from [voku/stop-words](https://github.com/voku/stop-words) library. Supported languages codes by this library are : ar, bg, ca, cz, da, de, el, en, eo, es, et, fi, fr, hi, hr, hu, id, it, ka, lt, lv, nl, no, pl, pt, ro, ru, sk, sv, tr, uk, vi.

```
$Keywords = new Keywords($text, $lang);
$kws = $Keywords->keywords;
```

If your language is not supported by [voku/stop-words](https://github.com/voku/stop-words) library or if you want to use your own stop words list, set 2nd argument as null and pass your own stop words array as 3rd argument.

```
$Keywords = new Keywords($text, 'auto', ['my custom stop word array']);
$kws = $Keywords->keywords;
```

You can optionnaly pass a 4th argument as the max numbers of keywords to be returned. Set to 20 by default. Pass 0 if you want all keywords. In all cases it only returns keywords with occurence above 1.

```
$Keywords = new Keywords($text, 'fr', [], 10);
$kws = $Keywords->keywords;
```

You can also pass an optionnal 5th argument array containing a list of chars you want to be removed from the analysed text. The default list is : | / &amp; : , ; ! ? \_ \* - - ... → – « » + ✔ # ¿ &lt; &gt; \[ \] { }

```
$Keywords = new Keywords($text, 'fr', [], 10, ['my custom chars list']);
$kws = $Keywords->keywords;
```

The optionnal 6th argument represents minimum keyword occurence to be returned. Default value is set to 2 so only keywords with minimum 2 occurences will be returned. If you want to get all keywords including those with only 1 occurence, set this parameter to 1.

```
$Keywords = new Keywords($text, 'fr', [], 10, ['my custom chars list'], 1);
$kws = $Keywords->keywords;
```

For the url , the library outputs :

```
[
    {
        "1": {
            "naturopathe": [
                12,
                "0.61"
            ],
            "m\u00e9decines": [
                11,
                "0.56"
            ],
            "naturopathie": [
                9,
                "0.46"
            ],
            "techniques": [
                9,
                "0.46"
            ],
            "m\u00e9decine": [
                9,
                "0.46"
            ],
            ...
        },
        "2": {
            "marie maugey": [
                5,
                "0.26"
            ],
            "maugey naturopathe": [
                4,
                "0.20"
            ],
            "\u2013 hippocrate": [
                3,
                "0.15"
            ],
            "m\u00e9decines alternatives": [
                2,
                "0.10"
            ],
            "m\u00e9decine conventionnelle": [
                2,
                "0.10"
            ],
            ...
        },
        "3": {
            "marie maugey naturopathe": [
                4,
                "0.20"
            ],
            "utilisation de techniques": [
                3,
                "0.15"
            ],
            "associe cette technique": [
                3,
                "0.15"
            ],
            "technique \u00e0 l\u2019\u00e9l\u00e9ment": [
                3,
                "0.15"
            ],
            "s'adresse la naturopathie": [
                2,
                "0.10"
            ],
            ...
        },
        "4": {
            "on associe cette technique": [
                3,
                "0.15"
            ],
            "associe cette technique \u00e0": [
                3,
                "0.15"
            ],
            "cette technique \u00e0 l\u2019\u00e9l\u00e9ment": [
                3,
                "0.15"
            ],
            "qui s'adresse la naturopathie": [
                2,
                "0.10"
            ],
            "la prise en charge": [
                2,
                "0.10"
            ],
            ...
        }
    }
]

```

Unit Tests
----------

[](#unit-tests)

```
vendor/phpunit/phpunit/phpunit --configuration phpunit.xml

```

Author
------

[](#author)

Hugo Maugey [visit my website ;)](https://hugo.maugey.fr)

### Online Tools

[](#online-tools)

### Dependecies

[](#dependecies)

### On same subject

[](#on-same-subject)

[https://github.com/sanketsharma411/keyword-density-analyzer/blob/flask-app/labs/4\_selecting\_nlp\_libraries.ipynb](https://github.com/sanketsharma411/keyword-density-analyzer/blob/flask-app/labs/4_selecting_nlp_libraries.ipynb)

###  Health Score

11

—

LowBetter than 0% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity21

Early-stage or recently created project

 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/cc04033020c3e5219ac30edf7d7362952e88ea64a0de2f41b89559f849f09901?d=identicon)[hugsbrugs](/maintainers/hugsbrugs)

---

Top Contributors

[![hugsbrugs](https://avatars.githubusercontent.com/u/4385090?v=4)](https://github.com/hugsbrugs "hugsbrugs (10 commits)")

### Embed Badge

![Health badge](/badges/hugsbrugs-php-keywords/health.svg)

```
[![Health](https://phpackages.com/badges/hugsbrugs-php-keywords/health.svg)](https://phpackages.com/packages/hugsbrugs-php-keywords)
```

PHPackages © 2026

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