PHP convert external relative path to absolute path

absolute-path, external, path, php

Solution

You should try the PECL function http_build_url http://php.net/manual/en/function.http-build-url.php

Problem

I am trying to figure out how to convert an "external relative path" to an absolute one: I'd really like a function that will do the following: ``` $path = "/search?q=query"; $host = "http://google.com"; $abspath = reltoabs($host, $path); ``` And have $abspath equal to "http://google.com/search?q=query" Another example: ``` $path = "top.html"; $host = "www.example.com/documentation"; $abspath = reltoabs($host, $path); ``` And have $abspath equal to "http://www.example.com/documentation/top.html" The problem is that it is not guaranteed to be in that format, and it could already be absolute, or be pointing to a different host entirely, and I'm not quite sure how to approach this. Thanks.

Original source