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!
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.
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.
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.
$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
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With