PHPackages                             makis83/helpers - 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. makis83/helpers

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

makis83/helpers
===============

A collection of PHP helper classes for files, texts, images etc.

1.0.1(9mo ago)0121MITPHPPHP ^8.2CI passing

Since Sep 15Pushed 3mo agoCompare

[ Source](https://github.com/makis83/PhpHelpers)[ Packagist](https://packagist.org/packages/makis83/helpers)[ RSS](/packages/makis83-helpers/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (5)Versions (3)Used By (1)

[![CI](https://github.com/makis83/PhpHelpers/actions/workflows/ci.yml/badge.svg)](https://github.com/makis83/PhpHelpers/actions/workflows/ci.yml)[![PHPStan](https://github.com/makis83/PhpHelpers/actions/workflows/phpstan.yml/badge.svg)](https://github.com/makis83/PhpHelpers/actions/workflows/phpstan.yml)[![Coverage](https://github.com/makis83/PhpHelpers/actions/workflows/coverage.yml/badge.svg)](https://github.com/makis83/PhpHelpers/actions/workflows/coverage.yml)

Makis83 PHP Helpers
===================

[](#makis83-php-helpers)

A collection of PHP helper classes for files, texts, images etc.

Installation
------------

[](#installation)

Use composer to install Makis83 PHP Helpers:

```
composer require makis83/helpers
```

Requirements
------------

[](#requirements)

- PHP 8.2 or higher
- Mbstring extension for working with text
- Tidy extension for working with HTML code

Documentation
-------------

[](#documentation)

### Data Helper

[](#data-helper)

#### `isJson(string $text): bool`

[](#isjsonstring-text-bool)

Check if the specified text is JSON.

```
// Valid JSON
$isJson = Data::isJson('{"key": "value"}'); // true
$isJson = Data::isJson('["item1", "item2"]'); // true
$isJson = Data::isJson('123'); // true

// Invalid JSON
$isJson = Data::isJson('This is not JSON.'); // false
$isJson = Data::isJson('{"key": "value"'); // false
```

#### `jsonEncode(array $data, int $options = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP): string`

[](#jsonencodearray-data-int-options--json_hex_tag--json_hex_apos--json_hex_quot--json_hex_amp-string)

Encode array as JSON.

```
// Simple array
$json = Data::jsonEncode(['item1', 'item2', 'item3']);
// Result: ["item1","item2","item3"]

// Associative array
$json = Data::jsonEncode(['key' => 'value']);
// Result: {"key":"value"}

// Nested array
$json = Data::jsonEncode(['user' => ['name' => 'John', 'age' => 30]]);
// Result: {"user":{"name":"John","age":30}}
```

#### `jsonDecode(string $data, bool $asArray = true): mixed`

[](#jsondecodestring-data-bool-asarray--true-mixed)

Decode the JSON-sequence.

```
// Simple array
$array = Data::jsonDecode('["item1","item2","item3"]');
// Result: ['item1', 'item2', 'item3']

// Associative array
$array = Data::jsonDecode('{"key":"value"}');
// Result: ['key' => 'value']

// Nested array
$array = Data::jsonDecode('{"user":{"name":"John","age":30}}');
// Result: ['user' => ['name' => 'John', 'age' => 30]]
```

#### `valueToArray(array|null|bool|int|float|string $value, string $delimiter = ','): array`

[](#valuetoarrayarraynullboolintfloatstring-value-string-delimiter---array)

Convert value into array.

```
// Single value
$array = Data::valueToArray('singleValue');
// Result: ['singleValue']

// Comma-separated values
$array = Data::valueToArray('value1, value2, value3');
// Result: ['value1', 'value2', 'value3']

// Array input (returns as-is)
$array = Data::valueToArray(['arrayValue1', 'arrayValue2']);
// Result: ['arrayValue1', 'arrayValue2']
```

### File Helper

[](#file-helper)

#### `fileExtension(string $path): string`

[](#fileextensionstring-path-string)

Get file extension from a file with the given path.

```
$extension = File::fileExtension('document.txt'); // Returns: "txt"
$extension = File::fileExtension('archive.tar.gz'); // Returns: "tar.gz"
$extension = File::fileExtension('ftp://server.tech/archive.tar.bz2'); // Returns: "tar.bz2"
```

#### `fileName(string $path, bool $withExtension = true): string`

[](#filenamestring-path-bool-withextension--true-string)

Get file name from the given path.

```
$name = File::fileName('document.txt'); // Returns: "document.txt"
$name = File::fileName('document.txt', false); // Returns: "document"
$name = File::fileName('ftp://server.tech/archive.tar.bz2'); // Returns: "archive.tar.bz2"
$name = File::fileName('ftp://server.tech/archive.tar.bz2', false); // Returns: "archive"
```

#### `isAbsolutePath(string $path, bool $allowSchemes = true): bool`

[](#isabsolutepathstring-path-bool-allowschemes--true-bool)

Check if the specified path is an absolute path.

```
$isAbsolute = File::isAbsolutePath('/var/www/html'); // true (Unix)
$isAbsolute = File::isAbsolutePath('C:\\Program Files\\App'); // true (Windows)
$isAbsolute = File::isAbsolutePath('relative/path/to/file'); // false
```

#### `ensureDirectory(string $path, int $mode = 0775, ?string $owner = null, ?string $group = null): true`

[](#ensuredirectorystring-path-int-mode--0775-string-owner--null-string-group--null-true)

Create a directory with the given path if it doesn't exist.

```
// Create a directory (will create all parent directories if needed)
File::ensureDirectory('/var/www/html/myapp/cache');
```

#### `removeDirectory(string $path): void`

[](#removedirectorystring-path-void)

Remove directory and all its files and subdirs recursively.

```
// Remove a directory and all its contents
File::removeDirectory('/var/www/html/myapp/cache');
```

#### `sanitizeFilename(string $fileName, string $replacement = '_'): string`

[](#sanitizefilenamestring-filename-string-replacement--_-string)

Sanitizes a filename by removing characters that are problematic for filesystems.

```
$sanitized = File::sanitizeFilename(' !! 🤬 invalid ¹²% _файлнаме??.txt ');
// Returns: "!!  invalid ¹²% _файлнаме__.txt"

$sanitized = File::sanitizeFilename('aux');
// Returns: "aux_"
```

### Html Helper

[](#html-helper)

#### `isHTML(string $text): bool`

[](#ishtmlstring-text-bool)

Detect whether the text is an HTML code.

```
$isHtml = Html::isHTML('This is a simple text.'); // false
$isHtml = Html::isHTML('This is a simple paragraph.'); // true
$isHtml = Html::isHTML('This is a  text & more.'); // true
```

#### `secure(string $data, bool $forceHtml = true, bool $purify = true, ?string $charset = null): string`

[](#securestring-data-bool-forcehtml--true-bool-purify--true-string-charset--null-string)

Secure the specified text data.

```
// Simple text
$secured = Html::secure('This is a simple text.');
// Result: "This is a simple text."

// Text with HTML-like entities
$secured = Html::secure('This is a "simple" text with entities & smth else™.');
// Result: "This is a "simple" text with entities & smth else&trade;."

// HTML with purification
$secured = Html::secure('This is a simple paragraph.');
// Result: "This is a simple paragraph."
```

#### `tidy(string $html, bool $repair = true, ?string $charset = null): string`

[](#tidystring-html-bool-repair--true-string-charset--null-string)

Tidy the specified HTML code.

```
// Simple text
$tidied = Html::tidy('This is a simple text.');
// Result: "This is a simple text."

// HTML with correct structure
$tidied = Html::tidy('This is a simple paragraph.');
// Result: "This is a simple paragraph.\n"

// HTML with incorrect structure
$tidied = Html::tidy('This is a simple paragraph.');
// Result: "This is a simple paragraph.\n"
```

#### `textToHtml(string $text, ?string $charset = null): string`

[](#texttohtmlstring-text-string-charset--null-string)

Convert a plain text into HTML.

```
// Simple text without line breaks
$html = Html::textToHtml('This is a simple text without line breaks.');
// Result: "This is a simple text without line breaks.\n"

// Text with line breaks
$html = Html::textToHtml("This is a simple text\nwith single line breaks.");
// Result: "This is a simple text\nwith single line breaks.\n"

// Multiple paragraphs
$html = Html::textToHtml("This is the first paragraph.\n\nThis is the second paragraph, with a line break.\nSee?\n\nThis is the third paragraph.");
// Result: "This is the first paragraph.\nThis is the second paragraph, with a line break.\nSee?\nThis is the third paragraph.\n"
```

#### `textTags(string $text): array`

[](#texttagsstring-text-array)

Get HTML tags used in the text.

```
// Simple text
$tags = Html::textTags('This is a simple text.');
// Result: []

// Simple HTML
$tags = Html::textTags('This is a simple paragraph.');
// Result: ['p', 'b']

// Complex HTML
$tags = Html::textTags('TitleParagraph with link and styled text.');
// Result: ['div', 'h1', 'p', 'a', 'span', 'img']
```

### Text Helper

[](#text-helper)

#### `setLeadingZeroes(int $number, int $numberLength = 2): string`

[](#setleadingzeroesint-number-int-numberlength--2-string)

Prepend the integer value with leading zeroes.

```
$zeroPadded = Text::setLeadingZeroes(5); // Returns: "05"
$zeroPadded = Text::setLeadingZeroes(5, 3); // Returns: "005"
$zeroPadded = Text::setLeadingZeroes(123, 3); // Returns: "123"
$zeroPadded = Text::setLeadingZeroes(1234, 3); // Returns: "1234"
```

#### `classNameToId(string $class): string`

[](#classnametoidstring-class-string)

Convert class name (with or without namespace) to ID.

```
$id = Text::classNameToId('MyClassName'); // Returns: "my-class-name"
$id = Text::classNameToId('App\\Models\\MyClassName'); // Returns: "my-class-name"
$id = Text::classNameToId('ABC'); // Returns: "a-b-c"
$id = Text::classNameToId('already-id'); // Returns: "already-id"
```

#### `fixSpaces(string $text): string`

[](#fixspacesstring-text-string)

Fixes issues with spaces, NBSPs etc.

```
// Basic usage
$fixed = Text::fixSpaces('This is a test.'); // Returns: "This is a test."

// With NBSPs
$fixed = Text::fixSpaces("This is a test."); // Returns: "This is a test."
$fixed = Text::fixSpaces("This \xC2\xA0 is \xC2\xA0 a \xC2\xA0 test."); // Returns: "This is a test."

// With narrow NBSPs
$fixed = Text::fixSpaces("This \xE2\x80\xAF is \xE2\x80\xAF a \xE2\x80\xAF test."); // Returns: "This is a test."

// With RLM characters
$fixed = Text::fixSpaces("This \xE2\x80\x8F is \xE2\x80\x8F\xe2\x80\x8a a \xE2\x80\x8F test.\xe2\x80\x83"); // Returns: "This is a test."
```

Tests
-----

[](#tests)

Run the tests using PHPUnit and PHPStan:

```
./composer test
```

or

```
./vendor/bin/phpunit --coverage-html coverage/html
./vendor/bin/phpstan analyse
```

License
-------

[](#license)

This project is licensed under the [MIT License](https://opensource.org/license/mit).

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance70

Regular maintenance activity

Popularity5

Limited adoption so far

Community8

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

291d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/15e2de80fc7b96ee2ca72a8d0f114ddf966e4b035e0d1467be66cc697f769e7e?d=identicon)[makis83](/maintainers/makis83)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/makis83-helpers/health.svg)

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

###  Alternatives

[grumpydictator/firefly-iii

Firefly III: a personal finances manager.

23.9k69.5k](/packages/grumpydictator-firefly-iii)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751291.4k43](/packages/civicrm-civicrm-core)[oat-sa/tao-core

TAO core extension

66143.7k122](/packages/oat-sa-tao-core)[verbb/formie

The most user-friendly forms plugin for Craft.

102393.6k69](/packages/verbb-formie)[firefly-iii/data-importer

Firefly III Data Import Tool.

8045.8k](/packages/firefly-iii-data-importer)[getdkan/dkan

DKAN Open Data Catalog

387138.7k2](/packages/getdkan-dkan)

PHPackages © 2026

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