URL parser for PHP, allow you to extract every piece of information of a URL/HOST, structured and clean.
max13/url-parser is a Laravel package for url parser for php, allow you to extract every piece of information of a url/host, structured and clean..
It currently has 2 GitHub stars and 650 downloads on Packagist (latest version v1.0.0).
Install it with composer require max13/url-parser.
Discover more Laravel packages by max13
or browse all Laravel packages to compare alternatives.
Last updated
MXUrlParser is capable of parsing a complete URL and extract some parts of it like the URL parts (using php parse_url() function) and some domain name parts (using Mozilla public suffix list).
Available parts are (Assuming URL is https://dev.api.example.co.uk/1/2/3?key=val#anchor):
scheme: httpshost: dev.api.example.co.ukpath: /1/2/3query: key=valfragment: anchorsubdomain: devdomain: api.exampletld: co.uk5.3There are several ways to download MxUrlParser-PHP:
"max13/url-parser": "dev-master")git clone <repo> [<dest>]Then place it where you want (readable location, in order to load it).
Let's say your URL is: dev.api.example.co.uk/1/2/3?key=val#anchor
You can parse it with the MX\UrlParser\UrlParser class:
<?php
use MX\UrlParser\UrlParser;
$p_url = new UrlParser('dev.api.example.co.uk/1/2/3?key=val#anchor');
/*
$p_url->scheme; // === null
$p_url->host; // == 'dev.api.example.co.uk'
$p_url->subdomain; // == 'dev'
$p_url->tld; // == 'co.uk'
*/
?>
That's it, as simple as this...!