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

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

geoffreyrose/url-helper
=======================

A URL helper to parse out different parts of a URL

v1.1.0(1y ago)1174MITPHPPHP ^8.0

Since Sep 5Pushed 1y ago1 watchersCompare

[ Source](https://github.com/geoffreyrose/url-helper)[ Packagist](https://packagist.org/packages/geoffreyrose/url-helper)[ GitHub Sponsors](https://github.com/geoffreyrose)[ RSS](/packages/geoffreyrose-url-helper/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/c405443d2781e734e4944fc48b2843ac48afff5f09bd28db0fa2b0c52261d2b5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f67656f6666726579726f73652f75726c2d68656c7065723f7374796c653d666c61742d737175617265)](https://packagist.org/packages/geoffreyrose/url-helper)[![GitHub Workflow Status](https://camo.githubusercontent.com/beac940dc883a0daf2cc526ca07c2b4dc888d0404c7385416e2da69269f6c029/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f67656f6666726579726f73652f75726c2d68656c7065722f6d61696e2e796d6c3f6272616e63683d6d61696e267374796c653d666c61742d737175617265)](https://github.com/geoffreyrose/url-helper/actions?query=branch%3Amain)[![Codecov branch](https://camo.githubusercontent.com/78d0e519b9af68e733af6e52ae0c2ddd581180c510d4758e0a77b338e3ac806c/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f67682f67656f6666726579726f73652f75726c2d68656c7065722f6d61696e3f7374796c653d666c61742d737175617265)](https://app.codecov.io/gh/geoffreyrose/url-helper/branch/main)[![License](https://camo.githubusercontent.com/ab0c75f3b52027978d00145d7bc300c1200cd49aa46966d4aa425066da45d04c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f67656f6666726579726f73652f75726c2d68656c7065723f7374796c653d666c61742d737175617265)](https://github.com/geoffreyrose/url-helper/blob/main/LICENSE)

PHP URL Helper + Laravel Facade
===============================

[](#php-url-helper--laravel-facade)

An easy-to-use PHP helper (and Laravel Facade) to parse out different parts of a URL

### Requirements

[](#requirements)

- PHP 8.0+

### Usage

[](#usage)

### Install

[](#install)

```
composer require geoffreyrose/url-helper

```

### With Plain PHP

[](#with-plain-php)

```
use UrlHelper\UrlHelper;

...

$urlHelper = new UrlHelper();
```

### With Laravel Facade

[](#with-laravel-facade)

Laravel uses Package Auto-Discovery, which doesn't require you to manually add the ServiceProvider and Facade.

```
$rootHostname = URLHelper::getRootHostname('https://github.com/geoffreyrose/url-helper/')
```

### Methods

[](#methods)

**Note all examples below use Plain PHP (use UrlHelper\\UrlHelper) but can be swapped with Laravel Facade (URLHelper)**

#### isValidDomainName()

[](#isvaliddomainname)

```
isValidDomainName(string $domain): bool

$urlHelper = new UrlHelper();

$urlHelper->isValidDomainName('https://example.com'); // false
$urlHelper->isValidDomainName('example.com'); // true
$urlHelper->isValidDomainName('Frodo Baggins'); // false

```

#### getHostname()

[](#gethostname)

```
getHostname(string $url): ?string

$urlHelper = new UrlHelper();

$urlHelper->getHostname('https://example.com'); // example.com
$urlHelper->getHostname('https://www.example.com')); // www.example.com
$urlHelper->getHostname('Bilbo Baggins'); // null

```

#### getScheme()

[](#getscheme)

```
getScheme(string $url): ?string

$urlHelper = new UrlHelper();

$urlHelper->getScheme('https://example.com'); // https
$urlHelper->getScheme('example.com'); // null
$urlHelper->getScheme('ftp://example.com'); // ftp
$urlHelper->getScheme('Dark Lord Sauron'); // null

```

#### getRootHostname()

[](#getroothostname)

```
getRootHostname(string $url): ?string

$urlHelper = new UrlHelper();

$urlHelper->getRootHostname('https://example.com'); // example.com
$urlHelper->getRootHostname('https://www.example.com')); // example.com
$urlHelper->getRootHostname('Samwise Gamge'); // null

```

#### getUrlWithoutScheme()

[](#geturlwithoutscheme)

```
getUrlWithoutScheme(string $url, bool $trimTrailingSlash=false): ?string

$urlHelper = new UrlHelper();

$urlHelper->getUrlWithoutScheme('https://example.com'); // example.com
$urlHelper->getUrlWithoutScheme('https://example.com/', true); // example.com
$urlHelper->getUrlWithoutScheme('https://example.com/test/?abc=123', true); // example.com/test?abc=123
$urlHelper->getUrlWithoutScheme('https://www.example.com')); // www.example.com
$urlHelper->getUrlWithoutScheme('Peregrin Took'); // null

```

#### getValidURL()

[](#getvalidurl)

```
getValidURL(string $url): ?string

$urlHelper = new UrlHelper();

$urlHelper->getValidURL('https://example.com'); // https://example.com
$urlHelper->getValidURL('https://www.example.com'); // https://www.example.com
$urlHelper->getValidURL('https://example.com/test'); // https://example.com/test
$urlHelper->getValidURL('example.com'); // null
$urlHelper->getValidURL('Merry Brandybuck')); // null

```

#### convertAndroidAppToHttps()

[](#convertandroidapptohttps)

```
convertAndroidAppToHttps(string $url): ?string

$urlHelper = new UrlHelper();

$urlHelper->convertAndroidAppToHttps('android-app://com.example'); // https://example.com
$urlHelper->convertAndroidAppToHttps('android-app://example.com'); // https://example.com
$urlHelper->convertAndroidAppToHttps('Dark Lord Sauron'); // null

```

#### getPathname()

[](#getpathname)

```
getPathname(string $url): ?string

$urlHelper = new UrlHelper();

$urlHelper->getPathname('https://example.com/path/to/somewhere'); // /path/to/somewhere
$urlHelper->getPathname('https://example.com'); // /
$urlHelper->getPathname('https://example.com/test/abc?test=12345')); // /test/abc

```

#### getParameters()

[](#getparameters)

```
getParameters(string $url): ?array

$urlHelper = new UrlHelper();

$urlHelper->getParameters('https://example.com/path/to/somewhere?test=12345&test2=abc'); // ['test' => '12345', 'test2' => 'abc']
$urlHelper->getParameters('https://example.com'); // null
$urlHelper->getPathname('Dark Lord Sauron'); // null

```

### Run Tests

[](#run-tests)

```
./vendor/bin/phpunit

// or with coverage

XDEBUG_MODE=coverage ./vendor/bin/phpunit

```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

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

Total

2

Last Release

540d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

laravelphpurlphpurl Helper

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[dusterio/link-preview

Link preview generation for PHP with Laravel support

126326.6k3](/packages/dusterio-link-preview)

PHPackages © 2026

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