I have a baseurl (e.g. http://google.at) and a path (e.g. search/user)
How can I combine both to http://google.at/search/user
and make sure it also works if the baseurl is http://google.at/ so it wouldn't produce http://google.at//search/user I do not want to manually perform string checks/manipulations, but I am rather looking for a function like path_combine
function path_combine($base, $path) {
return rtrim($base, '/') . '/' . $path;
}
var_dump(
path_combine('http://google.at', 'search/user'),
path_combine('http://google.at/', 'search/user')
);
// output:
// string(28) "http://google.at/search/user"
// string(28) "http://google.at/search/user"
(If you want flexibility on whether the path has a leading slash or not as well, then add an ltrim
accordingly.)