Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the base URL of an external website

Tags:

url

php

I'm using cURL to return data from external sites. How can I return the base URL of a site with PHP?

For example, I have this URL: http://www.bestbuy.com/site/Insignia%26%23153%3B+-+55%22+Class+/+1080p+/+120Hz+/+LCD+HDTV/2009148.p?id=1218317000232&skuId=2009148

I just want http://www.bestbuy.com

Thanks!

like image 514
Paul Dessert Avatar asked Feb 24 '12 06:02

Paul Dessert


People also ask

How do I find the base URL of a website?

To find the base URL of your website, go to the site's front page. What you see in the address bar on your site's front page is the base URL of your website.

How do I find the base URL in HTML?

The <base> tag specifies the base URL and/or target for all relative URLs in a document. The <base> tag must have either an href or a target attribute present, or both. There can only be one single <base> element in a document, and it must be inside the <head> element.

What is site base URL?

The URL found in the address bar of the front page of a website is its base URL. In other words, the common prefix found while navigating inside a given website is known as the base URL. One can select a base URL from the list of those available with help of the URL general properties page.


1 Answers


$url = "http://www.bestbuy.com/site/Insignia%26%23153%3B+-+55%22+Class+/+1080p+/+120Hz+/+LCD+HDTV/2009148.p?id=1218317000232&skuId=2009148";
echo "";
print_r(parse_url($url));

//Would give you Array ( [scheme] => http [host] => www.bestbuy.com [path] => /site/Insignia%26%23153%3B+-+55%22+Class+/+1080p+/+120Hz+/+LCD+HDTV/2009148.p [query] => id=1218317000232&skuId=2009148 )

like image 123
Sudhir Bastakoti Avatar answered Sep 20 '22 01:09

Sudhir Bastakoti