bickmista/spurl

A URL library that can validate, modify and split URL's. This library can split URL's into Subdomain, domain and TLD without choking when it comes to newer TLD's.

0.3.1 2015-09-17 14:04 UTC

This package is not auto-updated.

Last update: 2024-11-09 19:03:56 UTC


README

A URL manipulation library

Description

A PHP Library that can break down and build URLs into/from an array.

##Implementations

Current

  • Breakdown URLs
  • Build up URLs

Planned

  • Replace segments before build
  • Shuffle segments before build (e.g. swap host.domain with path.2)

Requirements

  • PHP 5.4+

Installation

Using Composer

To install Spurl with Composer, just add the following to your composer.json file

{
    "require": {
        "bickmista/spurl": "0.*"
    }
}

or by running the following command:

composer require bickmista/spurl

Usage

General

Shatter

To break down a URL into segments pass it into our shatter function.

$url = 'http://test.com/example/path?some=query#anchor';

$splitUrl = Spurl\Url::shatter($url);

The output from the shatter function in the example above would be

$splitUrl = [
  'protocol' => 'http',
  'host' => 'test.com',
  'path' => 'example/path',
  'query' => 'some=query',
  'anchor' => 'anchor'
];

You can also break down URLs further by passing true as an optional second parameter

$url = 'http://test.com/';

$splitUrl = Spurl\Url::shatter($url, true);

which would return

$splitUrl = [
  'protocol' => 'http',
  'host' => [
    'domain' => 'test',
    'suffix' => 'com'
  ]
];