How to Get Domain Name From URL in PHP

In this article, you will learn how to get domain name from a URL in PHP. Let’s say you have a string variable named ‘a’…

The post How to Get Domain Name From URL in PHP appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Ariessa Norramli

In this article, you will learn how to get domain name from a URL in PHP.

Let’s say you have a string variable named ‘a’ that has the value of codesource.io’s article URL.

$a = "https://codesource.io/javascript-design-patterns/";

Get Domain Name

In order to get the domain name from a URL, you can use the parse_url() method and host parameter.

$a = "https://codesource.io/javascript-design-patterns/";

$domain = parse_url($a);

echo "The domain is ".$domain['host'];
// The domain is codesource.io

Note: The parse_url() method functions by parsing a URL and returning an array of the URL components. The host parameter is used to access the hostname of the supplied URL.

The post How to Get Domain Name From URL in PHP appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Ariessa Norramli


Print Share Comment Cite Upload Translate Updates
APA

Ariessa Norramli | Sciencx (2021-03-02T11:33:20+00:00) How to Get Domain Name From URL in PHP. Retrieved from https://www.scien.cx/2021/03/02/how-to-get-domain-name-from-url-in-php/

MLA
" » How to Get Domain Name From URL in PHP." Ariessa Norramli | Sciencx - Tuesday March 2, 2021, https://www.scien.cx/2021/03/02/how-to-get-domain-name-from-url-in-php/
HARVARD
Ariessa Norramli | Sciencx Tuesday March 2, 2021 » How to Get Domain Name From URL in PHP., viewed ,<https://www.scien.cx/2021/03/02/how-to-get-domain-name-from-url-in-php/>
VANCOUVER
Ariessa Norramli | Sciencx - » How to Get Domain Name From URL in PHP. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/03/02/how-to-get-domain-name-from-url-in-php/
CHICAGO
" » How to Get Domain Name From URL in PHP." Ariessa Norramli | Sciencx - Accessed . https://www.scien.cx/2021/03/02/how-to-get-domain-name-from-url-in-php/
IEEE
" » How to Get Domain Name From URL in PHP." Ariessa Norramli | Sciencx [Online]. Available: https://www.scien.cx/2021/03/02/how-to-get-domain-name-from-url-in-php/. [Accessed: ]
rf:citation
» How to Get Domain Name From URL in PHP | Ariessa Norramli | Sciencx | https://www.scien.cx/2021/03/02/how-to-get-domain-name-from-url-in-php/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.