PHPackages                             fofx/utility - 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. fofx/utility

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

fofx/utility
============

Utilities library

v0.4.4(2mo ago)0161MITHTMLPHP ^8.3

Since Aug 12Pushed 2mo agoCompare

[ Source](https://github.com/fofxtools/utility)[ Packagist](https://packagist.org/packages/fofx/utility)[ RSS](/packages/fofx-utility/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (14)Versions (45)Used By (1)

Utility
=======

[](#utility)

A PHP library with a few practical helpers. Uses [jeremykendall/php-domain-parser](https://github.com/jeremykendall/php-domain-parser) for domain parsing.

- `get_tables()` - List database tables for the current connection
- `download_public_suffix_list()` - Ensure the Public Suffix List exists locally
- `extract_registrable_domain()` - Extract a registrable domain from a URL
- `is_valid_domain()` - Validate if a domain has a valid registrable domain and suffix
- `extract_canonical_url()` - Extract the canonical URL from HTML content
- `list_embedded_json_selectors()` - List CSS selectors for JSON script tags found in HTML
- `extract_embedded_json_blocks()` - Extract JSON blocks from HTML with additional metadata
- `filter_json_blocks_by_selector()` - Filter JSON blocks by selector ID, with optional 'json' key selection
- `save_json_blocks_to_file()` - Save extracted JSON blocks to a file with optional filtering by selector ID

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

[](#installation)

```
composer require fofx/utility
```

Usage
-----

[](#usage)

See usage examples in:

- [docs/usage.md](docs/usage.md)
- [docs/usage-json-to-columns.md](docs/usage-json-to-columns.md)
- [docs/usage-FiverrSitemapImporter.md](docs/usage-FiverrSitemapImporter.md)
- [docs/usage-FiverrJsonImporter.md](docs/usage-FiverrJsonImporter.md)
- [docs/usage-AmazonProductPageParser.md](docs/usage-AmazonProductPageParser.md)
- [docs/usage-AmazonBrowseNodeImporter.md](docs/usage-AmazonBrowseNodeImporter.md)
- [docs/usage-tracking.md](docs/usage-tracking.md)
- [docs/wordpress-php-sdk.md](docs/wordpress-php-sdk.md)

### Extracting and Filtering Embedded JSON from HTML

[](#extracting-and-filtering-embedded-json-from-html)

You can use `filter_json_blocks_by_selector()` with `extract_embedded_json_blocks()` to extract embedded JSON from an HTML file, and filter it.

```
require_once __DIR__ . '/../vendor/autoload.php';

use FOfX\Utility;
use Illuminate\Support\Arr;

$filename = __DIR__ . '/../resources/2-httpswwwfiverrcomcategoriesgraphics-designcreative-logo-design-fiverrcom-browserhtml.html';
$html = file_get_contents($filename);
$blocks = Utility\extract_embedded_json_blocks($html);
$filtered = Utility\filter_json_blocks_by_selector($blocks, 'perseus-initial-props', true);
// Use Arr::dot() to get a dot notation list of keys, to see the JSON structure
$dot_keys_only = array_keys(Arr::dot($filtered[0] ?? []));
print_r($dot_keys_only);
```

### Importing Fiverr Sitemap Data (Categories and Tags)

[](#importing-fiverr-sitemap-data-categories-and-tags)

See [docs/usage-FiverrSitemapImporter.md](docs/usage-FiverrSitemapImporter.md)

```
use FOfX\Utility\FiverrSitemapImporter;

$importer = new FiverrSitemapImporter();
$importer->setBatchSize(500); // optional (default 100)

// Categories
$stats = $importer->importCategories();
print_r($stats);

// Tags
$stats = $importer->importTags();
print_r($stats);
```

### JSON to Columns

[](#json-to-columns)

Helpers for working with JSON data and converting it to database columns.

See [docs/usage-json-to-columns.md](docs/usage-json-to-columns.md)

```
use FOfX\Utility;

$filename = __DIR__ . '/../resources/2-httpswwwfiverrcomcategoriesgraphics-designcreative-logo-design-fiverrcom-browserhtml.html';
$html     = file_get_contents($filename);
$blocks   = Utility\extract_embedded_json_blocks($html);
$filtered = Utility\filter_json_blocks_by_selector($blocks, 'perseus-initial-props', true);
// Infer Laravel database columns types from the filtered JSON
// At the first item, first listing, first gig
$types   = Utility\inspect_json_types($filtered[0]['listings'][0]['gigs'][0], delimiter: '__', infer: true);
$columns = Utility\types_to_columns($types);
print_r($columns);
```

This gives you hints about the column types. Using `__` delimiter, which is friendly for column names. Partial output:

```
integer('gigId')
integer('pos')
string('type')
string('auction__id')
boolean('is_fiverr_choice')
integer('packages__recommended__id')
boolean('packages__recommended__extra_fast')
integer('packages__recommended__price')
integer('packages__recommended__duration')
integer('packages__recommended__price_tier')
string('packages__recommended__type')
string('sellerId')
...

```

Testing and Development
-----------------------

[](#testing-and-development)

To run the PHPUnit test suite through composer:

```
composer test
```

To use PHPStan for static analysis:

```
composer phpstan
```

To run PHPStan on the `tests` folder:

```
composer phpstan tests
```

To use PHP-CS-Fixer for code style:

```
composer cs-fix
```

### Test and the PSL file

[](#test-and-the-psl-file)

Since tests use temporary storage, to avoid network calls during tests. `public_suffix_list.dat` ([download here](https://publicsuffix.org/list/public_suffix_list.dat)) must be saved to to `local/resources/`.

Tests then copy this file into temporary storage. If it is missing, tests are skipped.

License
-------

[](#license)

MIT

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance86

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity54

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

Recently: every ~23 days

Total

44

Last Release

74d ago

### Community

Maintainers

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

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/fofx-utility/health.svg)

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

###  Alternatives

[laravel/browser-kit-testing

Provides backwards compatibility for BrowserKit testing in the latest Laravel release.

5139.4M286](/packages/laravel-browser-kit-testing)[spatie/laravel-pjax

A pjax middleware for Laravel 5

513371.8k11](/packages/spatie-laravel-pjax)[blair2004/nexopos

The Free Modern Point Of Sale System build with Laravel, TailwindCSS and Vue.js.

1.2k2.3k](/packages/blair2004-nexopos)[visuellverstehen/statamic-classify

A useful helper to add CSS classes to all HTML tags generated by the bard editor.

20116.8k](/packages/visuellverstehen-statamic-classify)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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