Library to correctly join relative and absolute URLs
A PHP library function for joining a base URL and a potentially-relative target URL into an absolute URL, (*1)
Why isn't this in the PHP standard library? WHO KNOWS., (*2)
Installation:, (*3)
src/urljoin.php
into your projectcomposer require busybee/urljoin
usage:, (*4)
urljoin($base_url, $other_url);
See tests.php for test suite, as well as expected inputs and outputs. (Doing
this correctly is way more complicated thing than you'd think!) This
implementation strives for accuracy and, in cases of ambiguity (such as ../
stack underflow and empty path components), defers to Python's standard library
behavior (as implemented by urlparse.urljoin
)., (*5)
Other things that you might know this as:, (*6)
rel2abs
and relativeToAbsolute
(common names for this sort of function)