<?php
|
/*---------------------------------------------------------------*/
|
/*
|
Titre : Conversion d'URL relative en URL absolue
|
|
URL : https://phpsources.net/code_s.php?id=635
|
Auteur : developpeurweb
|
Date édition : 17 Avril 2011
|
Date mise à jour : 22 Aout 2019
|
Rapport de la maj:
|
- fonctionnement du code vérifié
|
*/
|
/*---------------------------------------------------------------*/
|
|
function absolute_url($base_url, $relative_url){
|
$base_url_info = parse_url($base_url);
|
$base_url_path = explode("/", $base_url_info["path"]);
|
$base_url_file = $base_url_path[count($base_url_path)-1];
|
unset($base_url_path[count($base_url_path)-1]);
|
$relative_url_path = explode("/", $relative_url);
|
if (parse_url($relative_url, PHP_URL_SCHEME) != ""){
|
return $relative_url;
|
}else{
|
switch($relative_url_path[0]){
|
case ".":
|
unset($relative_url_path[0]);
|
return absolute_url
|
( $base_url
|
, implode("/",$relative_url_path)
|
);
|
break;
|
case "..":
|
unset($relative_url_path[0]);
|
return absolute_url
|
( str_replace($base_url_info["path"], "", $base_url)
|
. implode("/", $base_url_path)
|
, implode("/", $relative_url_path)
|
);
|
break;
|
case "":
|
return str_replace($base_url_info["path"], "", $base_url)
|
. $relative_url
|
;
|
break;
|
default:
|
return str_replace($base_url_info["path"], "", $base_url)
|
. implode("/", $base_url_path)
|
. "/"
|
. $relative_url
|
;
|
break;
|
}
|
}
|
}
|
?>
|
|
|