0

Hy!

I parse a website with simplehtml dom to get all links from the pictures.

The problem is that the link is like "/pics/bla.jpg".

I have the full path from the website like "http://xxx.xxx/blob/gulsch".

Now i want to get the full image link from the image (link root + /pics/bla.jpg) (no concat) like: http://xxx.xxx/pics/bla.jpg

This should work for many websites

I tried it with explode()

$root = explode("/", $link);
echo $root[2];

I never get it working.

Please help.

test123123
  • 911
  • 3
  • 16
  • 33
  • possible duplicate of [PHP - Prepend a url to all links with no http or https](http://stackoverflow.com/questions/3681049/php-prepend-a-url-to-all-links-with-no-http-or-https) – Gordon Nov 18 '11 at 11:06
  • just wanted to know... why don't u wanna do concat? – Arjun Bajaj Nov 18 '11 at 11:33

2 Answers2

0

Given the parts of a URL, you can build a full URL with http_build_url.

John Watson
  • 2,554
  • 1
  • 17
  • 13
0

Try with parse_url:

$r = parse_url($websiteUrl);
$imageUrl = $r["scheme"] . "://" . $r["host"] . "/" . $imageRelativeUrl;

The "root" of the website is simply $r["host"].

laurent
  • 88,262
  • 77
  • 290
  • 428