PHPackages                             spresnac/laravel-url-helper - 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. spresnac/laravel-url-helper

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

spresnac/laravel-url-helper
===========================

Helping you with URL related problems

0.9.1(3y ago)21.1kMITPHPPHP ^8.1CI failing

Since Nov 11Pushed 3y ago1 watchersCompare

[ Source](https://github.com/spresnac/laravel-url-helper)[ Packagist](https://packagist.org/packages/spresnac/laravel-url-helper)[ GitHub Sponsors](https://github.com/spresnac)[ Fund](https://www.buymeacoffee.com/spresnac)[ RSS](/packages/spresnac-laravel-url-helper/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (2)Versions (18)Used By (0)

URL Helper Package
==================

[](#url-helper-package)

[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![PHP from Packagist](https://camo.githubusercontent.com/c3e014fb3f8118ac807c8a75e54248b92da1eb7a44b6d2c12b6bbc9856fd0a0f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f73707265736e61632f6c61726176656c2d75726c2d68656c7065722e737667)](https://camo.githubusercontent.com/c3e014fb3f8118ac807c8a75e54248b92da1eb7a44b6d2c12b6bbc9856fd0a0f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f73707265736e61632f6c61726176656c2d75726c2d68656c7065722e737667)[![codecov](https://camo.githubusercontent.com/bc145afdde83c950704acdf3113f41d12df71596f921150b978b7fd831029952/68747470733a2f2f636f6465636f762e696f2f67682f73707265736e61632f6c61726176656c2d75726c2d68656c7065722f6272616e63682f6d61696e2f67726170682f62616467652e7376673f746f6b656e3d36424558353530363242)](https://codecov.io/gh/spresnac/laravel-url-helper)[![CI Status](https://github.com/spresnac/laravel-url-helper/workflows/tests/badge.svg)](https://github.com/spresnac/laravel-url-helper/actions)

---

Content:
========

[](#content)

- [Installation](#installation)
- [Usage](#usage)
    - [Content Helper](#content-helper)
    - [URL Helper](#url-helper)
    - [Sitemap Helper](#sitemap-helper)
- [Tests](#tests)
- [Finally](#finally)

---

Installation
============

[](#installation)

First things first, so require the package:

```
composer require spresnac/laravel-url-helper
```

---

Usage
=====

[](#usage)

Content Helper
--------------

[](#content-helper)

Every time you need to get URLs from some kind of Text or HTML, this class is a helping hand for you.

1. Make an instance of the class
2. Use the constructor or the `setContent` method to put in your content as string.
3. Get your URLs by using one of the following methods.

---

### getContent(): string

[](#getcontent-string)

This will just the content you put in via constructor or `setContent` method.

---

### getHrefs(): Collection

[](#gethrefs-collection)

You will retrieve a Collection with only the URLs inside a `href`

```
$content_helper = new ContentHelper('insert HTML here');
$result = $content_helper->getHrefs();
// $result is an Collection with all the hrefs in it.
```

---

### getHrefsAsArray(): array

[](#gethrefsasarray-array)

You will retrieve an array with only the URLs inside a `href`

```
$content_helper = new ContentHelper('insert HTML here');
$result = $content_helper->getHrefsAsArray();
// $result is an Collection with all the hrefs in it.
```

---

### getSrcUrls(): Collection

[](#getsrcurls-collection)

You will retrieve a collection of urls from `src` sources.

```
$content_helper = new ContentHelper('insert HTML here');
$result = $content_helper->getSrcUrls();
// $result is an Collection with all the src-urls in it.
```

---

### getLinksFromPlaintext(): Collection

[](#getlinksfromplaintext-collection)

This method will try to find all the urls in a plaintext string.

```
$content_helper = new ContentHelper('insert some plaintext here');
$result = $content_helper->getLinksFromPlaintext();
// $result is an Collection with all the urls from the plaintext in it.
```

---

### getAllTheLinks(): Collection

[](#getallthelinks-collection)

This will execute `getHrefs`, `getSrcUrls` and `getLinksFromPlaintext` and will return a uniqueified collection of all the urls.

```
$content_helper = new ContentHelper('insert some html or plaintext here');
$result = $content_helper->getAllTheLinks();
// $result is an Collection with all the urls.
```

---

URL Helper
----------

[](#url-helper)

Some useful helper functions to handle URL related manipulating or info-gatherings.

---

### normalize\_url(string $url): string|false

[](#normalize_urlstring-url-stringfalse)

Normalizes URL with .. in it and leaves the all oher URL "as is".

```
$url_helper = new URLHelper();
$normalized_url = $url_helper->normalize('https://example.com/my/dir/with/two/../init.html');
// $normalized_url is now https://example.com/my/dir/with/init.html
```

Returns `false` in case of error

---

### build\_url(array $parsed\_url): string

[](#build_urlarray-parsed_url-string)

This is the missing opposite of `parse_url` to rebuild a url from its parts.

```
$url_helper = new URLHelper();
$parsed_url = parse_url('https://example.com/test/url.php');
$my_url = $url_helper->build_url($parsed_url);
```

---

### getMainDomainPart(string $url): string

[](#getmaindomainpartstring-url-string)

This will return the "Main Domain" part of an URL. The "Main Domain" is like the SLD + TLD domain part.

```
$url_helper = new URLHelper();
$main_domain_part = $url_helper->getMainDomainPart('https://www3.example.com/some/url');
// $main_domain_part is now "example.com"
```

---

### getSubdomainPart(string $url): string

[](#getsubdomainpartstring-url-string)

This will return the Subdomain part of an URL.

```
$url_helper = new URLHelper();
$sub_domain_part = $url_helper->getMainDomainPart('https://www3.brick.example.com/some/url');
// $sub_domain_part is now "www3.brick"
```

---

Sitemap Helper
--------------

[](#sitemap-helper)

Handling with web-sitemaps can be handy with some helpers at your side.

---

### process\_input\_from\_string(string $input\_string): Collection

[](#process_input_from_stringstring-input_string-collection)

Will return all the urls inside a sitemap as Collection

```
$sitemap_helper = new SitemapHelper();
$urls = $sitemap_helper->process_input_from_string('content_of_your_sitemap_as_string');
// $urls are a collection of all the urls found
```

---

### process\_input\_from\_url(string $input\_url): Collection (0.5+)

[](#process_input_from_urlstring-input_url-collection-05)

Returns the urls in a sitemap url as Collection

```
$sitemap_helper = new SitemapHelper();
$urls = $sitemap_helper->process_input_from_url('url_to_your_sitemap');
// $urls are a collection of all the urls found
```

---

Tests
=====

[](#tests)

Simply run

```
composer test-ci
```

or

```
vendor/bin/phpunit
```

---

Finally
=======

[](#finally)

Be productive 😉

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 92.1% 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 ~59 days

Total

16

Last Release

1174d ago

PHP version history (6 changes)0.1PHP ^7.4

0.5PHP ^7.4 || ^8.0

0.7.4PHP ^7.4 | ^8.0 | ^8.1

0.7.5PHP ^7.4 | ^8

0.8.1PHP ^8

0.9.1PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/04d0510a1a5bdd5707fb726d639d971007e602343c4378f65a56c64fa5638170?d=identicon)[spresnac](/maintainers/spresnac)

---

Top Contributors

[![spresnac](https://avatars.githubusercontent.com/u/3299107?v=4)](https://github.com/spresnac "spresnac (82 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (5 commits)")[![mend-bolt-for-github[bot]](https://avatars.githubusercontent.com/in/16809?v=4)](https://github.com/mend-bolt-for-github[bot] "mend-bolt-for-github[bot] (2 commits)")

---

Tags

hacktoberfesthelperlaravellaravel-packagephpphp-libraryurlphplaravel

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/spresnac-laravel-url-helper/health.svg)

```
[![Health](https://phpackages.com/badges/spresnac-laravel-url-helper/health.svg)](https://phpackages.com/packages/spresnac-laravel-url-helper)
```

###  Alternatives

[amranidev/laracombee

Recommendation system for laravel

11538.8k1](/packages/amranidev-laracombee)[yieldstudio/tailwind-merge-php

Merge Tailwind CSS classes without style conflicts

4975.4k1](/packages/yieldstudio-tailwind-merge-php)[salmanzafar/laravel-geocode

A Laravel Library to find Lat and Long of a given Specific Address

154.4k](/packages/salmanzafar-laravel-geocode)[wujunze/money-wrapper

MoneyPHP Wrapper

103.8k](/packages/wujunze-money-wrapper)

PHPackages © 2026

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