Extract domain name from url using php

Click to rate this tutorial!
[Total: 1 Average: 5]

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&#91;scheme&#93;";
echo "
url - $parts&#91;host&#93;";
echo "
path - $parts&#91;path&#93;";
echo "
query - $parts&#91;query&#93;";
?>

OutPut

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

Click to rate this tutorial!
[Total: 1 Average: 5]

Leave a Reply

Your email address will not be published.