function createAbsoluteURL($src, $url) {
$scheme = parse_url($url)["scheme"];
$host = parse_url($url)["host"];
if (substr($src, 0, 2) == "//") {
$src = $scheme . ":" . $src;
} else if (substr($src, 0, 1) == "/") {
$src = $scheme . "://" . $host . $src;
} else if (substr($src, 0, 2) == "./") {
$dirname = dirname(parse_url($url)["path"]);
$dirname = ($dirname == "\\" || $dirname == "/") ? "" : $dirname;
$src = $scheme . "://" . $host . $dirname . substr($src, 1);
} else if (substr($src, 0, 3) == "../") {
$src = $scheme . "://" . $host . substr($src, 2);
} else if (substr($src, 0, 5) != "https" && substr($src, 0, 4) != "http") {
$src = $scheme . "://" . $host . "/" . $src;
}
return $src;
}
$url = "https://www.collectivesolver.com/";
echo createAbsoluteURL("//www.collectivesolver.com", $url) . "<br>";
echo createAbsoluteURL("/about.html", $url) . "<br>";
echo createAbsoluteURL("./test.php", $url) . "<br>";
echo createAbsoluteURL("../abc.php", $url) . "<br>";
echo createAbsoluteURL("xyz.php", $url) . "<br><br>";
$url = "http://localhost/allonpage/";
echo createAbsoluteURL("//www.collectivesolver.com", $url) . "<br>";
echo createAbsoluteURL("/about.html", $url) . "<br>";
echo createAbsoluteURL("./test.php", $url) . "<br>";
echo createAbsoluteURL("../abc.php", $url) . "<br>";
echo createAbsoluteURL("xyz.php", $url) . "<br>";
/*
run:
https://www.collectivesolver.com
https://www.collectivesolver.com/about.html
https://www.collectivesolver.com/test.php
https://www.collectivesolver.com/abc.php
https://www.collectivesolver.com/xyz.php
http://www.collectivesolver.com
http://localhost/about.html
http://localhost/test.php
http://localhost/abc.php
http://localhost/xyz.php
*/