A simple PHP library to parse and manipulate URLs

Related tags

URL url
Overview

Url version 3

League\Url 3 is EOL since 2015-09-23

This repository is for the legacy Url version 3, the new version is available at https://github.com/thephpleague/uri.

Build Status Coverage Status Quality Score Software License Latest Version Total Downloads

Url is a simple library to ease creating and managing Urls in PHP.

This package is compliant with PSR-2, and PSR-4.

Requirements

You need PHP >= 5.3.0 and the mbstring extension to use the library, but the latest stable version of PHP is recommended.

Install

Install Url using Composer.

composer require league/url

This will edit (or create) your composer.json file and automatically choose the most recent version in the 3.x serie.

Going Solo

You can also use League\Url without using Composer by downloading the library and using a PSR-4 compatible autoloader.

Documentation

League\Url is fully documented. Contribute to this documentation in the gh-pages branch.

Testing

$ phpunit

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

Comments
  • Let return all set method $this to allow a fluent use of the interface

    Let return all set method $this to allow a fluent use of the interface

    Hi Ignace,

    I would like you to consider my PR to implement a fluent interface for all setter methods. I changed it mainly to later query parts.

    With the current version, you always have to store the query-object to alter it:

    $url = \League\Url\UrlImmutable::createFromServer($_SERVER);
    $query = $url->getQuery();
    $query->set(['page' => 123]);
    $newurl = $url->setQuery($query);
    

    The fluent interface would allow to alter the query string in a single line:

    $url = \League\Url\UrlImmutable::createFromServer($_SERVER);
    $newurl = $url->setQuery($url->getQuery()->set(['page' => $page]));
    

    Thanks for considering! Greets, Dennis

    opened by DennisBirkholz 12
  • Adds support for

    Adds support for "localhost" hostname

    Modifies the package implementation of Host to allow for "special" hostnames.

    As a developer, I do still use "localhost" from time to time, and occasionally use it in my code for testing purposes. Today, running some testing, the URL "http://localhost:8080/path" got an exception from this package.

    So, the first "special" hostname (maybe it'll be the only one we will ever need) I recommend is "localhost", because it is a standard development hostname.

    Initially, I tried to make the package work nicely with one part hostnames in general, but that was not working out because we already had the following test, and I didn't want to break BC:

        /**
         * @expectedException RuntimeException
         */
        public function testCreateFromUrlBadName2()
        {
            Url::createFromUrl('sdfsdfqsdfsdf');
        }
    

    The URL specs don't say anything about this being illegal. Well, they do, in the sense that you need a scheme; but if "google.com" is legal to use with this method, then "localhost" should be too.

    opened by christickner 4
  • Enhancement: Set environment variable for collection code coverage

    Enhancement: Set environment variable for collection code coverage

    This PR

    • [x] uses an environment variable COLLECT_COVERAGE to determine whether coverage should be collected and sets it in the build matrix, rather than duplicating the actual command
    opened by localheinz 3
  • Improve code base readability

    Improve code base readability

    Changes contain

    • Improve consistency of vertical spacing
    • Minimize else and elseif conditionals
    • Remove variables created just for return statements
    • Use === instead of ==

    Test cases affected

    • None
    opened by swarajgiri 3
  • Warn users that this package is EOL at installation step

    Warn users that this package is EOL at installation step

    When I was setting up a new project, I had to use URL manipulation. From another project I knew there was this awesome URL package from the thephpleague. So I googled and found this right away. Since I knew this package was good, I installed it immediately and got it working.

    Then I ran composer update a week later, and it told me that this package was EOL.

    So this PR makes sure that other won't make the same silly mistake I made 🙈 ;)

    opened by ruudk 1
  • Enhancement: Speed up builds on Travis

    Enhancement: Speed up builds on Travis

    This PR

    • [x] directs builds on Travis to container-based infrastructure
    • [x] enables caching of dependencies installed with composer between builds
    • [x] preferably installs dependencies from dist, rather than from source

    Before

    https://travis-ci.org/thephpleague/url/builds/70920428:

    screen shot 2015-07-14 at 17 15 32 ### After

    See https://travis-ci.org/thephpleague/url/builds/70978916:

    screen shot 2015-07-14 at 17 13 09
    opened by localheinz 1
  • Altered return hinting

    Altered return hinting

    Since this method can be invoked form a child class, the return type of "AbstractUrl" does not allow the IDE to provide proper autocomplete of the Url or UrlImmutable classes.

    By returning static IDEs can figure this out from the invoke context, as well as it indicating that this class can be invoked form children.

    opened by rdohms 1
  • Urls with dots in the query string keys are not correctly parsed

    Urls with dots in the query string keys are not correctly parsed

    Because parse_str() allows to create variables from strings, PHP automaticly replaces dots with underscores. This is a problem if you have to parse query strings like "?foo.bar=baz". I hope the pull request targets the correct branch, I'm quite new to this.

    opened by janhohner 1
Releases(3.3.5)
  • 3.3.5(Jul 15, 2015)

  • 3.3.4(Jul 1, 2015)

  • 3.3.3(Jun 25, 2015)

  • 4.0.0-beta.3(Jun 10, 2015)

    Added

    • isEmpty method to League\Url\Interfaces\Url to tell whether a URL is empty or not
    • isSupported static method to League\Url\Scheme to tell whether a specified scheme is supported by the library
    • Add support for the gopher scheme

    Fixed

    • Improve Punycode decoding/encoding issue #73

    Remove

    • Support for the pseuod git and svn protocol
    Source code(tar.gz)
    Source code(zip)
  • 4.0.0-beta.2(Jun 5, 2015)

  • 4.0.0-beta.1(Jun 3, 2015)

    Added

    • Package structure is changed to better reflect the importance of each component.
    • Package is now more RFC3986 compliant
    • League\Url\UserInfo class added to better manipulate URL user info part
    • League\Url\Output\Formatter class added to ease URL and URL components formatting.
    • All Url related classes are now immutable value objects.
    • League\Url\Url implements Psr\Http\Message\UriInterface
    • Methods to ease complete or partial component modifications are added to League\Url\Url
    • Url components and Url Parts can now be compared to each other using the sameValueAs method
    • League\Url\Host, League\Url\Path component public API are simplified.
    • League\Url\Host now supports IP style hosts and FQDN
    • League\Url\Host::__toString method now always return the ascii version of the hostname
    • More methods are added to the League\Url\Path object to extract generic path info as well as modifying the path according to RFC3986 (i.e.: removing dot segments)
    • League\Url\Query public API is simplified to remove ambiguity
    • League\Url\Query no longer depends on php parse_str and http_build_query
    • League\Url\Scheme and League\Url\Port are rewritten completely

    Fixed

    • Handling of legacy hostname suffixed with a "." when using Url::createFromServer

    Remove

    • League\Url\User and League\Url\Pass are replaced by the more generic League\Url\Component
    • Support for PHP 5.3
    • League\Url\UrlImmutable class is replaced by League\Url\Url which is now immutable
    • Most of the public API is removed :
      • to comply to RFC3986;
      • to enable immutable value object;
      • to implement PSR7 UriInterface;

    Please refers to the documentation or the library CHANGELOG for more details and a complete list of changes

    Source code(tar.gz)
    Source code(zip)
  • 3.3.2(May 13, 2015)

  • 3.3.1(Mar 26, 2015)

  • 3.3.0(Mar 20, 2015)

  • 3.2.1(Nov 27, 2014)

  • 3.2.0(Nov 12, 2014)

  • 3.1.1(Sep 2, 2014)

  • 3.1.0(Jul 10, 2014)

    Adding IDN support #17

    • The library now requires the mbstring extension to work.

    The following methods were added:

    • League\Url\Components\Host::toAscii
    • League\Url\Components\Host::toUnicode as an alias of League\Url\Components\Host::__toString

    More informations can be found on the documentation website

    Source code(tar.gz)
    Source code(zip)
  • 3.0.1(Jun 30, 2014)

  • 3.0.0(Jun 25, 2014)

    Changelog from version 2 to version 3

    Summary

    • Support for FTP Urls
    • Adding a UrlImmutable value object
    • Library rewrote from scratch

    New

    • League\Url\UrlInterface introduced
    • League\Url\Url now implements League\Url\UrlInterface
    • League\Url\UrlImmutable implements League\Url\UrlInterface
    • League\Url\Components\ComponentInterface introduced to normalized All URLs components objects
    • League\Url\Components\User to deal with URL User component object
    • League\Url\Components\Path to deal with URL Path component object

    Backward incompatible

    • URL component setter and getter names normalized according to PHP Url component as used by parse_url
    • Each getter returns an object that implements at least the League\Url\Components\ComponentInterface
    • To instantiate a League\Url\Url object or League\Url\UrlImmutable object use the static methods createFromUrl and/or createFromServer

    The following class are removed:

    • League\Url\Factory
    • League\Url\Components\Auth

    More informations can be found on the documentation website

    Source code(tar.gz)
    Source code(zip)
  • 3.0.0-rc.2(Jun 18, 2014)

    Changelog

    • League\Url\Factory becomes League\Url\AbstractUrl which implements League\Url\UrlInterface
    • League\Url\Url and League\Url\UrlImmutable extends League\Url\AbstractUrl
    • League\Url\AbstractUrl::createFromString renamed League\Url\AbstractUrl::createFromUrl
    • removed League\Url\EncodingInterface from League\Url\AbstractUrl
    • moved League\Url\EncodingInterface to League\Url\Components\EncodingInterface
    • adding optional $enc_type argument to League\Url\Url::setQuery and League\Url\UrlImmutable::setQuery
    • adding exchange methods to all Components classes
    • bug fix League\Url\Components\AbstractSegment::set method
    • documentation updated to reflect the changes
    Source code(tar.gz)
    Source code(zip)
  • 3.0.0-rc.1(Jun 12, 2014)

    Remove duplicated methods

    methods like League\Url\Url::prependPath that were only proxy to URL component object method have been removed.

    • League\Url\Url::modifyQuery
    • League\Url\Url::prependPath
    • League\Url\Url::appendPath
    • League\Url\Url::removePath
    • League\Url\Url::prependHost
    • League\Url\Url::appendHost
    • League\Url\Url::removeHost

    One Library Two Url value objects

    • League\Url\Url is a mutable Value Object. (similar to its V2 version)
    • League\Url\UrlImmutable is an immutable Value Object.
    //From a League\Url\Url object 
    $url = $url_factory->createFromString('https://www.example.com');
    $url
        ->setUser('john')
        ->setPass('doe')
        ->setPort(443)
        ->setScheme('https');
    echo $url; // https://john:[email protected]:443/
    
    $port = $url->getPort();
    $port->set(80);
    echo $port; // output 80;
    echo $url->getPort(); // output 80;
    
    //From a League\Url\UrlImmutable object 
    $url = $url_factory->createFromString('http://www.example.com', Factory::URL_IMMUTABLE);
    $new_url = $url
            ->setUser('john')
            ->setPass('doe')
            ->setPort(443)
            ->setScheme('https');
    echo $url; //remains http://www.example.com/
    echo $new_url; //output https://john:[email protected]:443/
    
    $port = $new_url->getPort(); //$port is a clone object of the URL port component.
    $port->set(80);
    echo $port; // output 80;
    echo $new_url->getPort(); // remains 443;
    

    Factory has been rewritten

    The League\Url\Factory is now a full object with a constructor. and returns a value object depending on 2 new constants:

    • Factory::URL_MUTABLE
    • Factory::URL_IMMUTABLE
    require 'vendor/autoload.php' //when using composer
    
    use League\Url\Factory;
    
    $url_factory = new Factory(PHP_QUERY_RFC1738);
    
    //Method 1 : from a given string
    $url = $url_factory->createFromString('http://www.example.com');
    $url_immutable = $url_factory->createFromString('http://www.example.com', Factory::URL_IMMUTABLE);
    
    $url_factory->setEncoding(PHP_QUERY_RFC3968);
    
    //Method 2: from the current PHP page
    //don't forget to provide the $_SERVER array
    $url = $url_factory->createFromServer($_SERVER); 
    $url_immutable = $url_factory->createFromServer($_SERVER, Factory::URL_IMMUTABLE);
    

    Many components have been improved and bug fixed

    Source code(tar.gz)
    Source code(zip)
  • 3.0.0-beta.3(Jun 9, 2014)

  • 3.0.0-beta.2(Jun 3, 2014)

    • adding League\Url\Url::sameValueAs method to compare two League\Url\Url objects
    • improved URL path encoding and decoding
    • improved URL host validation
    Source code(tar.gz)
    Source code(zip)
  • 3.0.0-beta.1(Jun 1, 2014)

    Immutable Value Object

    League\Url\Url is now a Immutable Value Object. This means that any change made to the object will return a new object with the changed property and will leave the original object unchanged.

    use League\Url\Factory as Url;
    $original_url = Url::createFromString('http://www.example.com');
    $modified_url = $original_url->setQuery(array('foo' => 'bar'));
    echo $original_url; // output http://www.example.com/
    echo $modified_url; // output http://www.example.com/?foo=bar
    

    Prior to version 3, some url component properties where returned as string and other as object. Now all component property are returned:

    • as object that implement a common Interface which includes the __toString method;
    • as cloned from the internal property to avoid breaking the League\Url\Url Immutable state;
    use League\Url\Factory as Url;
    $original_url = Url::createFromString('http://www.example.com');
    $host = $original_url->getHost();
    $host->remove('www');
    $host->prepend('test');
    echo $original_url; // output http://www.example.com/
    echo $host; // output test.example.com
    

    Url parsing has been improved as well as League\Url\Url::__toString() methods.

    Source code(tar.gz)
    Source code(zip)
  • 2.1.2(Feb 16, 2014)

  • 2.1.1(Nov 28, 2013)

  • 2.1.0(Nov 28, 2013)

    • Bakame\Url\Components\Host and Bakame\Url\Components\Path now extends an Abstract Class called Bakame\Url\Components\AbstractSegment
    • Bakame\Url\Components\AbstractSegment::prepend and Bakame\Url\Components\AbstractSegment::append methods have been rewrote
    • Bakame\Url\Url is now clonable
    • Bakame\Url\Components\Query now has a remove method
    Source code(tar.gz)
    Source code(zip)
  • 2.0.2(Nov 21, 2013)

  • 2.0.1(Nov 20, 2013)

  • 2.0.0(Nov 20, 2013)

    • move the Components Classes to their own directory
    • modify Components classes __toString() method to make the component class more decoupled from each other
    • modify \Bakame\Url\Url class to take advantage of the component class more easily
    • now \Bakame\Url\Url class is clonable
    • \Bakame\Url\Components\Query now implements ArrayAcces, IteratorAggregae, Countable interfaces
    • you can merge different \Bakame\Url\Components\Query with the set method
    • \Bakame\Url\Components\Path and \Bakame\Url\Components\Host extends the \Bakame\Url\Components\Segment class
    Source code(tar.gz)
    Source code(zip)
  • 1.0.1(Nov 19, 2013)

  • 1.0.0(Nov 19, 2013)

Owner
The League of Extraordinary Packages
A group of developers who have banded together to build solid, well tested PHP packages using modern coding standards.
The League of Extraordinary Packages
Laravel based API to shorten URLs and share them easily. Redirects to the real URL by entering a short URL generated by the API

URL Shortener Requirements: PHP 7.4 or above composer node / npm Installation clone the project from the Github repository, enter the project folder,

Julio Vergara 5 Nov 20, 2021
A PHP-based self-hosted URL shortener that can be used to serve shortened URLs under your own custom domain.

A PHP-based self-hosted URL shortener that can be used to serve shortened URLs under your own custom domain. Table of Contents Full documentation Dock

null 1.7k Dec 29, 2022
A laravel package for generating Bitly short URLs.

Laravel Bitly Package A laravel package for generating Bitly short URLs. For more information see Bitly Requirements Laravel 5.1 or later Installation

Wessel Strengholt 72 Nov 8, 2022
A Laravel package to shorten urls

Laravel Short Url Laravel Short Url is a package allowing you to shorten urls. Installation With composer composer require gallib/laravel-short-url t

Alain Pellaux 153 Dec 16, 2022
Purl is a simple Object Oriented URL manipulation library for PHP 7.2+

Purl Purl is a simple Object Oriented URL manipulation library for PHP 7.2+ Installation The suggested installation method is via composer: composer r

Jonathan H. Wage 908 Dec 21, 2022
A simple URL shortener for PHP

Shorty Shorty is a simple URL shortener for PHP. Installation 1. Download and extract the files to your web directory. 2. Use the included database.sq

Mike Cao 210 Dec 19, 2022
URI manipulation Library

URI The Uri package provides simple and intuitive classes to manage URIs in PHP. You will be able to parse, build and resolve URIs create URIs from di

The League of Extraordinary Packages 886 Jan 6, 2023
[DEPRECATED] Library for extraction of domain parts e.g. TLD. Domain parser that uses Public Suffix List

DEPRECATED Consider to use https://github.com/jeremykendall/php-domain-parser as maintained alternative. TLDExtract TLDExtract accurately separates th

Oleksandr Fediashov 216 Oct 18, 2022
A simple but powerful URL shortener

UrlShorter 这是一个足够简洁的Url短网址生成器 This is a simple Url shorter. 兼容性 在PHP7.X 与 PHP 8.0 下测试通过 安装 step 1: git clone [email protected]:soxft/UrlShorter.git step

xcsoft 74 Dec 21, 2022
A fast and powerful URL Shortener built with Laravel, VueJS, and Tailwind CSS.

A fast and powerful URL Shortener built with Laravel, VueJS, and Tailwind CSS.

Devpri 53 Dec 25, 2022
:aerial_tramway: A modern, powerful, and robust URL shortener

?? A modern, minimalist, and lightweight URL shortener. Polr is an intrepid, self-hostable open-source link shortening web application with a robust A

Chaoyi Zha 4.6k Jan 1, 2023
php5 class to read and write .torrent files

Torrent RW PHP version 5.2+ Features: Decode torrent file or data Build torrent from source folder/file(s) Silent Exception error system Usage example

Adrien Gibrat 273 Dec 23, 2022
A modern, powerful, and robust URL shortener

?? A modern, minimalist, and lightweight URL shortener. Polr is an intrepid, self-hostable open-source link shortening web application with a robust A

Chaoyi Zha 4.6k Dec 30, 2022
Public Suffix List based domain parsing implemented in PHP

PHP Domain Parser PHP Domain Parser is a resource based domain parser implemented in PHP. Motivation While there are plenty of excellent URL parsers a

Jeremy Kendall 1k Jan 1, 2023
:earth_asia: Functions for making sense out of URIs in PHP

sabre/uri sabre/uri is a lightweight library that provides several functions for working with URIs, staying true to the rules of RFC3986. Partially in

sabre.io 283 Dec 22, 2022
shortUrl - PHP - Witout-API ☔

shortUrl - PHP - Witout-API ☔

ARAR AL-DOSRI 3 Jun 27, 2022
URL shortener web application based on the Laravel PHP Framework.

UrlHub Warning: UrlHub is still in development, constantly being optimized and isn't still stable enough to be used in production environments. Whatev

Kei 349 Jan 4, 2023
The modern, privacy-aware URL Shortener built in PHP.

About UrlHum UrlHum is a modern, privacy-aware and fast URL Shortener built with PHP and the Laravel Framework. At the moment UrlHum is heavily under

UrlHum 622 Jan 7, 2023
URL shortener web application based on the Laravel PHP Framework.

UrlHub Warning: UrlHub is still in development, constantly being optimized and isn't still stable enough to be used in production environments. Whatev

Kei 348 Dec 23, 2022