PHPackages                             zegnat/linkextractor - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. zegnat/linkextractor

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

zegnat/linkextractor
====================

A package that tries to figure out what resources an HTML document links to.

0.3.0(1mo ago)471[4 issues](https://github.com/Zegnat/php-linkextractor/issues)0BSDHTMLPHP &gt;=7.0

Since Nov 14Pushed 1mo ago3 watchersCompare

[ Source](https://github.com/Zegnat/php-linkextractor)[ Packagist](https://packagist.org/packages/zegnat/linkextractor)[ RSS](/packages/zegnat-linkextractor/feed)WikiDiscussions develop Synced 4w ago

READMEChangelogDependencies (4)Versions (6)Used By (0)

LinkExtractor
=============

[](#linkextractor)

The LinkExtractor tries to figure out what resources an HTML document links to.

This tries to solve 2 questions:

1. what constitutes a link between an HTML document and another resource, and
2. how to supply them in a useful (resolved) format.

The class is able to get (and resolve) every URL from a pre-parsed DOM in accordance with where the HTML5 specification allows URLs to be defined. The HTML5 specification is followed after [a GitHub discussion](https://github.com/w3c/webmention/issues/91)about what a link is, and further in person discussion at [IWC Berlin 2017](https://indieweb.org/2017/Berlin).

Using versions &lt; 1.0
-----------------------

[](#using-versions--10)

The current function prototypes are the same as those that will be in 1.0.0. This means you can write the method calls in your code right now and update to 1.0.0 without breaking any of your calls later.

```
function extract(): array
function linksTo(string $url): bool
```

If you rely on specific output or exceptions from these methods however, there might be breaking changes before version 1.0.0. Take a look at [the roadmap to version 1.0.0](https://github.com/Zegnat/php-linkextractor/milestone/1) to get an idea of what is likely to still be changed.

Don’t wait for 1.0.0 with using this library if you need it! Instead, start using it and leave the ever-important feedback.

Install
-------

[](#install)

Via Composer

```
$ composer require zegnat/linkextractor
```

Usage
-----

[](#usage)

```
// Parse the HTML into a DOMDocument:
$dom = new \DOMDocument();
$dom->loadHTML(file_get_contents('http://example.com/index.html'));
// Initiate the extractor with the document and its URL:
$extractor = new \Zegnat\LinkExtractor\LinkExtractor($dom, 'http://example.com/index.html');
var_dump(
    $extractor->linksTo('https://github.com/'),
    $extractor->linksTo('http://www.iana.org/domains/example')
);
/*
bool(false)
bool(true)
*/
```

On PHP 8.4 and newer you can instead pass a document parsed with the new `\Dom\HTMLDocument` API and its standards-compliant HTML parser:

```
$dom = \Dom\HTMLDocument::createFromString(
    file_get_contents('http://example.com/index.html')
);
$extractor = new \Zegnat\LinkExtractor\LinkExtractor($dom, 'http://example.com/index.html');
```

Supported PHP versions
----------------------

[](#supported-php-versions)

This library requires PHP 7.0 or newer and is tested against PHP 7.0, 7.1, 7.2, 7.3, 7.4, 8.0, 8.1, 8.2, 8.3, 8.4 and 8.5.

From PHP 8.4 onwards it accepts both `\DOMNode` and `\Dom\Node`.

Testing
-------

[](#testing)

Tests run on every supported PHP version through Docker, orchestrated by [Castor](https://castor.jolicode.com/). Each PHP version and its dependencies live entirely in their container, so only Docker and Castor are needed on the host:

```
$ castor matrix     # run the whole matrix
$ castor test 8.4   # run a single version
$ castor coverage   # run with code coverage and enforce the minimum
```

Some test fixtures under `tests/files` are copied verbatim from external open-source projects under their respective licenses; see [CREDITS.md](CREDITS.md)for their sources and the `LICENSES` directory ([REUSE](https://reuse.software/)).

License
-------

[](#license)

The BSD Zero Clause License (0BSD). Please see the LICENSE file for more information.

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance74

Regular maintenance activity

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity52

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

Total

3

Last Release

33d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/490579?v=4)[Martijn van der Ven](/maintainers/Zegnat)[@Zegnat](https://github.com/Zegnat)

---

Top Contributors

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

---

Tags

domhtmlhtml5

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/zegnat-linkextractor/health.svg)

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

###  Alternatives

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.2k555.0M2.8k](/packages/aws-aws-sdk-php)[guzzlehttp/guzzle

Guzzle is a PHP HTTP client library

23.5k1.1B37.5k](/packages/guzzlehttp-guzzle)[ccxt/ccxt

A cryptocurrency trading API with more than 100 exchanges in JavaScript / TypeScript / Python / C# / PHP / Go

43.5k344.8k1](/packages/ccxt-ccxt)[craftcms/cms

Craft CMS

3.6k3.7M3.4k](/packages/craftcms-cms)[eslazarev/wildberries-sdk

Wildberries OpenAPI clients (generated).

353.6k](/packages/eslazarev-wildberries-sdk)[algolia/algoliasearch-client-php

API powering the features of Algolia.

69735.8M179](/packages/algolia-algoliasearch-client-php)

PHPackages © 2026

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