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.
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!