PHP converts a relative path URL to an absolute path URL
PHP converts a relative path URL to an absolute path URL
PHP code
/*** Convert a URL to a complete URL * convert the relative path URL to an absolute path URL */function format_url ($ srcurl, $ baseurl) {$ srcinfo = parse_url ($ srcurl); if (isset ($ srcinfo ['scheme ']) {return $ srcurl;} $ baseinfo = parse_url ($ baseurl ); $ url = $ baseinfo ['scheme ']. '://'. $ baseinfo ['host']; if (substr ($ srcinfo ['path'], 0, 1) = '/') {$ path = $ srcinfo ['path'];} else {$ filename = basename ($ baseinfo ['path']); // Compatible basic url is the list if (strpos ($ filen Ame ,". ") = false) {$ path = dirname ($ baseinfo ['path']). '/'. $ filename. '/'. $ srcinfo ['path'];} else {$ path = dirname ($ baseinfo ['path']). '/'. $ srcinfo ['path'] ;}}$ rst = array (); $ path_array = explode ('/', $ path); if (! $ Path_array [0]) {$ rst [] = '';} foreach ($ path_array AS $ key => $ dir) {if ($ dir = '.. ') {if (end ($ rst) = '.. ') {$ rst [] = '.. ';} elseif (! Array_pop ($ rst) {$ rst [] = '...' ;}} elseif ($ dir & $ dir! = '.') {$ Rst [] = $ dir ;}} if (! End ($ path_array) {$ rst [] = '';} $ url. = implode ('/', $ rst); return str_replace ('\', '/', $ url );}