PHP: parse_url - resource locator analysis

The function allows you to automatically perform the basic conversion of the URL and write its contents to an associative array. An array gets the main components of a universal resource locator. The analysis and use of each component of the URL is determined by the programmer as necessary to achieve the desired result.

Function scope

The PHP parse_url () function allows you to get important information: protocol, port, site domain name, parameter string and other data contained in the URL. First of all, the domain name is in demand, but the parameter string is also important.

The main task of the function is to form an associative array with the keys: scheme, host, port, user, pass, path, query and fragment. If the user and pass components have a specific application, then the domain name and domain zone are very important.

The topic of parsing has been extremely popular lately, but before analyzing the content of any web resource, it is important to identify its URL through PHP parse_url (): determine the domain name and its geographic area.

Parsing sites




Inside the domain zone, the domain name is unique and acts as a key to the content of the web resource, and geography allows you to keep statistics on the countries from which customers come.





The path and query components can help determine the analysis of the structure of the site’s pages, explore the reasons (request text) for which a particular visitor came to the site.

URL Components and Example




In this example, the parse_url () function is applied to two variants of real URLs. You can see how convenient it is to get all the components of the original string parsed by the elements of the array.

Analysis of incoming customers

Parsing the Internet is an interesting and practically profitable activity. Actually engage in the collection of commercial data, it is practical to conduct research. The PHP function parse_url () finds its application for each site owner in the context of studying the client base and its needs.

Parsing Visitors




As a rule, actions to disseminate information about one's own resource involve money expenses and posting information on third-party sites. Nothing prevents the owner from providing links to his resource that are unique in each case.

Using the PHP parse_url () function, the owner can monitor client flows from all the resources on which he posted the information.




All Articles