PHPackages                             fathkoc/php-textmagic - 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. fathkoc/php-textmagic

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

fathkoc/php-textmagic
=====================

A lightweight PHP library for basic text analysis operations like summarization, sentiment analysis, keyword extraction, and classification.

02PHP

Since Oct 4Pushed 1y ago1 watchersCompare

[ Source](https://github.com/fathkoc/php-TextMagic-)[ Packagist](https://packagist.org/packages/fathkoc/php-textmagic)[ RSS](/packages/fathkoc-php-textmagic/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

**TextMagic**
=============

[](#textmagic)

**TextMagic** is a PHP-based text analysis library designed to perform basic but powerful operations like text summarization, sentiment analysis, keyword extraction, and text classification using simple algorithms such as Naive Bayes and TF-IDF. This library is designed for developers looking for a lightweight and efficient solution for text analysis tasks.

**Features**
------------

[](#features)

- **Text Summarization:** Extracts the most important sentences from a given text.
- **Sentiment Analysis:** Detects whether the sentiment of the text is positive, negative, or neutral.
- **Keyword Extraction:** Finds the most frequent words in the text to highlight key concepts.
- **Text Classification:** Classifies the text into categories like "news", "sports", and "entertainment."

**Installation**
----------------

[](#installation)

To install **TextMagic**, run the following command:

```
composer require fathkoc/php-textmagic
```

**Usage**
---------

[](#usage)

### 1. **Text Summarization**

[](#1-text-summarization)

This feature allows you to summarize the text by selecting the most relevant sentences.

```
use TextMagic\TextAnalyzer;

$analyzer = new TextAnalyzer();
$text = "This is the first sentence. This is the second sentence. This is the third sentence.";

echo $analyzer->summarize($text, 2);  // Will return the top 2 sentences.
```

### 2. **Sentiment Analysis**

[](#2-sentiment-analysis)

Analyzes the sentiment of the text and returns whether it's positive, negative, or neutral.

```
$sentiment = $analyzer->sentimentAnalysis("I love this! It makes me happy.");
echo $sentiment;  // Will return 'positive'.
```

### 3. **Keyword Extraction**

[](#3-keyword-extraction)

Extracts the top 5 keywords from a text.

```
$keywords = $analyzer->extractKeywords("Artificial Intelligence is a branch of computer science.");
print_r($keywords);  // Will return an array of the most frequent words.
```

### 4. **Text Classification**

[](#4-text-classification)

Classifies the text into one of the predefined categories using a Naive Bayes classifier.

```
$category = $analyzer->classify("The football match was exciting.");
echo $category;  // Will return the predicted category (e.g., 'sports').
```

**How It Works**
----------------

[](#how-it-works)

- **Text Summarization:** Uses the TF-IDF algorithm to weigh each sentence's importance based on the words it contains.
- **Sentiment Analysis:** Uses a simple keyword matching system with predefined positive and negative words.
- **Keyword Extraction:** Tokenizes the text and counts the frequency of each word to return the most frequent ones.
- **Text Classification:** Uses a Naive Bayes classifier to predict the category of the text based on training data.

**Limitations**
---------------

[](#limitations)

While **TextMagic** provides useful insights from text, it uses basic algorithms and techniques that are not powered by advanced AI or machine learning models. It’s ideal for lightweight applications but may not provide the accuracy of more complex NLP models.

###  Health Score

14

—

LowBetter than 2% of packages

Maintenance29

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity17

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

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/fathkoc-php-textmagic/health.svg)

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

###  Alternatives

[webbycrown/blog-for-bagisto

Blog for Bagisto

257.0k](/packages/webbycrown-blog-for-bagisto)

PHPackages © 2026

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