Extract subdomain and relative address from a url

I am writing a plugin where I need to split a URL submitted to a form into all the component parts of the URL including subdomain, extension etc. In addition, I need to construct the relative address for the URL submitted.

I know about the WordPress function

wp_parse_url()

but as per the example in the developer documentation, if I submit the URL https://developer.wordpress.org/reference/functions/wp_parse_url/ I only get some of the information that I need namely:

array (
‘scheme’ => ‘https’,
‘host’ => ‘developer.wordpress.org’,
‘path’ => ‘/reference/functions/wp_parse_url/’,
)

The built-in PHP function:

parse_url()

doesn’t offer anything more. Does anyone know of some other function or algorithm that will allow me to extract everything out of the URL including the sub-domain, extension etc. all at once?

Read more here:: Extract subdomain and relative address from a url

Leave a Reply

Your email address will not be published. Required fields are marked *