Home  >  Article  >  Backend Development  >  How to remove domain name from url in php

How to remove domain name from url in php

王林
王林Original
2020-10-21 15:00:274785browse

php method to remove the domain name in the url: first use the parse_url() function to convert the url into an associative array; then remove the domain name. The parse_url() function is used to parse the url and return its components.

How to remove domain name from url in php

The parse_url function converts the URL into an associative array

(Recommended tutorial: php video tutorial)

parse_url parses the URL and returns its components.

Description

parse_url ( string $url [, int $component = -1 ] )

This function parses a URL and returns an associative array containing the various components that appear in the URL.

This function is not used to verify the legitimacy of the given URL. Incomplete URLs are also accepted, and parse_url() will try to parse them as correctly as possible.

Code implementation:

php > $foo = "http://www.example.com/foo/bar?hat=bowler&accessory=cane"; 
php > $blah = parse_url($foo);
php > print_r($blah);
Array(    
    [scheme] => http    
    [host] => www.example.com    
    [path] => /foo/bar    
    [query] => hat=bowler&accessory=cane
)

Related recommendations: php training

The above is the detailed content of How to remove domain name from url in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn