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

How to remove domain name from url in php

王林
Release: 2023-03-06 18:54:01
Original
4849 people have browsed it

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 ] )
Copy after login

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
)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template