Download the PHP package voku/php-domain-parser without Composer

On this page you can find all versions of the php package voku/php-domain-parser. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-domain-parser

Build Status codecov.io Scrutinizer Code Quality Codacy Badge SensioLabsInsight Latest Stable Version Total Downloads Latest Unstable Version PHP 7 ready License

PHP Domain Parser

WARNING: this is only a Fork of "https://github.com/jeremykendall/php-domain-parser"

PHP Domain Parser is a Public Suffix List based domain parser implemented in PHP.

Motivation

While there are plenty of excellent URL parsers and builders available, there are very few projects that can accurately parse a url into its component subdomain, registrable domain, and public suffix parts.

Consider the domain www.pref.okinawa.jp. In this domain, the public suffix portion is okinawa.jp, the registrable domain is pref.okinawa.jp, and the subdomain is www. You can't regex that.

Other similar libraries focus primarily on URL building, parsing, and manipulation and additionally include public suffix domain parsing. PHP Domain Parser was built around accurate Public Suffix List based parsing from the very beginning, adding a URL object simply for the sake of completeness.

Installation

The only (currently) supported method of installation is via Composer.

Create a composer.json file in the root of your project:

And then run: composer install

Add the autoloader to your project:

You're now ready to begin using the PHP Domain Parser.

Usage

Parsing URLs

Parsing URLs into their component parts is as simple as the example you see below.

The above will output:

Convenience Methods

A magic __get() method is provided to access the above object properties. Obtaining the public suffix for a parsed domain is as simple as:

IDNA Support

IDN (Internationalized Domain Name) support was added in version 1.4.0. Both unicode domains and their ASCII equivalents are supported.

Unicode

Parsing IDNA hosts is no different that parsing standard hosts. Setting $host = 'Яндекс.РФ'; (Russian-Cyrillic) in the Parsing URLs example would return:

ASCII (Punycode)

If you choose to provide the ASCII equivalent of the unicode domain name ($host = 'http://xn--d1acpjx3f.xn--p1ai'; in the case of the Parsing URLs example), the ASCII equivalent will be returned by the parser:

IPv6 Support

Parsing IPv6 hosts is no different that parsing standard hosts. Setting $host = 'http://[2001:db8:85a3:8d3:1319:8a2e:370:7348]:8080/'; in the Parsing URLs example would return:

IMPORTANT: IPv6 url host names must be enclosed in square brackets. They will not be parsed properly otherwise.

Hat tip to @geekwright for adding IPv6 support in a bugfix pull request.

Parsing Domains

If you'd like to parse the domain (or host) portion only, you can use Parser::parseHost().

The above will output:

Validation of Public Suffixes

Public Suffix validation is available by calling Parser::isSuffixValid():

A suffix is considered invalid if it is not contained in the Public Suffix List.

Huge thanks to @SmellyFish for submitting Add a way to validate TLDs to add public suffix validation to the project.

Retrieving Domain Components Only

If you're only interested in a domain component, you can use the parser to retrieve only the component you're interested in

The above will output:

Sanity Check

You can quickly parse a url from the command line with the provided parse vendor binary. From the root of your project, simply call:

If you pass a url to parse, that url will be parsed and the output printed to screen.

If you do not pass a url, http://user:[email protected]:8080/path/to/page.html?query=string#fragment will be parsed and the output printed to screen.

Example:

Example Script

For more information on using the PHP Domain Parser, please see the provided example script.

Refreshing the Public Suffix List

While a cached PHP copy of the Public Suffix List is provided for you in the data directory, that copy may or may not be up to date (Mozilla provides an Atom change feed to keep up with changes to the list). Please use the provided vendor binary to refresh your cached copy of the Public Suffix List.

From the root of your project, simply call:

You may verify the update by checking the timestamp on the files located in the data directory.

Important: The vendor binary update-psl depends on an internet connection to update the cached Public Suffix List.

Possible Unexpected Behavior

PHP Domain Parser is built around PHP's parse_url() function and, as such, exhibits most of the same behaviors of that function. Just like parse_url(), this library is not meant to validate URLs, but rather to break a URL into its component parts.

One specific, counterintuitive behavior is that PHP Domain Parser will happily parse a URL with spaces in the host part.

Contributing

Pull requests are always welcome! Please review the CONTRIBUTING.md document before submitting pull requests.

Heads up: BC Break In All 1.4 Versions

The 1.4 series introduced a backwards incompatible change by adding PHP's ext-mbstring and ext-intl as dependencies. This should have resulted in a major version bump. Instead I bumped the minor version from 1.3.1 to 1.4.

I highly recommend reverting to 1.3.1 if you're running into extension issues and do not want to or cannot install ext-mbstring and ext-intl. You will lose IDNA and IPv6 support, however. Those are only available in versions >= 1.4.

I apologize for any issues you may have encountered due my semver error.

Attribution

The HTTP adapter interface and the cURL HTTP adapter were inspired by (er, lifted from) Will Durand's excellent Geocoder project. His MIT license and copyright notice are below.

Portions of the PublicSuffixListManager and the DomainParser are derivative works of the PHP registered-domain-libs. Those parts of this codebase are heavily commented, and I've included a copy of the Apache Software Foundation License 2.0 in this project.


All versions of php-domain-parser with dependencies

PHP Build Version
Package Version
Requires php Version >=7.0.0
true/punycode Version ~2.1
voku/arrayy Version ~7.4
voku/portable-utf8 Version ~5.4
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package voku/php-domain-parser contains the following files

Loading the files please wait ....