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
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/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.