Extract domain name from url using php

This Tutorial Has Been Viewed 966 Times.

parse_url is a built in php function which can be used to parse url and get the type of request like whether its http or https or ftp, gives the domain name like www.google.com and path and the query.

below is the sample code

< ?php
$url = "http://www.mistonline.in/index.php?php=4";
$parts = parse_url($url);
print_r($parts);
echo "
scheme - $parts[scheme]";
echo "
url - $parts[host]";
echo "
path - $parts[path]";
echo "
query - $parts[query]";
?>

OutPut

scheme -> http
url -> www.mistonline.in
path -> /index.php
query -> php=4

VN:F [1.9.13_1145]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.13_1145]
Rating: -2 (from 2 votes)

Incoming search terms:





You will also be interested in ,

Tags: ,

Leave a Reply

Spam protection by WP Captcha-Free

Proudly designed by Mistonline.in.
Affordable Seo PackagesSeo BlogEdu Backlinks
More in PHP, scripts (64 of 150 articles)


A simple message ticker in which each message is associated with a unique URL, and clicking the button will take ...