Search code examples
phparrayspreg-match

How to get a domain name from url string?


I have several urls like,

https://example.com/
http://example.com/

I only want "example.com" as string

And I want to remove the

https:// and http://

So I have taken array like this,

$removeChar = ["https://", "http://", "/"];

What is the proper way to remove these?


Solution

  • This worked for me,

    $http_referer = str_replace($removeChar, "", "https://example.com/");