Max13 / MXUrlParser-PHP

URL Parser in PHP, extracts URL parts + hostname parts
3 stars 1 forks source link

MXUrlParser-PHP

Description

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):

Required

How to download

There are several ways to download MxUrlParser-PHP:

Then place it where you want (readable location, in order to load it).

How to use

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...!