Removing subdomains from a form

How can I only extract the base URl from a long string that has been entered into a form?

Example: User inputs: http://stackoverflow.com/question/ask/asdfasneransea

The program only needs:, http://stackoverflow.com

not/question/ask/asdfasneransea

What's the easy way to do it using PHP?

0


source to share


2 answers


You can just use parse_url()



$url = parse_url('http://example.com/foo/bar');
$host = $url['host']; // example.com

      

+5


source


Use the parse_url function to get the individual parts of the url and then collect the details you want.



+1


source







All Articles