<?php foreach([ 'scheme://user@host/path', 'scheme://host/path', '/path', 'path', '//host/path', 'x:/path', 'scheme:///path', 'file:///path', 'file:/path', 'file:path', ] as $url) { print "\n: $url\n"; if($url === '--') continue; $path = parse_url($url); if($path === false) { print '"Seriously malformed URL." (q) https://php.net/parse_url' . "\n"; continue; } $ta = []; if(isset($path['scheme'])) $ta = array_merge($ta, [$path['scheme'], ":"]); if(isset($path['host']))// || (isset($path['scheme']) && isset($path['path']))) $ta[] = "//"; if(isset($path['user'])) $ta[] = $path['user']; if(isset($path['pass'])) $ta = array_merge($ta, [":", $path['pass']]); if(isset($path['user'])) $ta[] = "@"; if(isset($path['host'])) $ta[] = $path['host']; if(isset($path['port'])) $ta = array_merge($ta, [":", $path['port']]); if(isset($path['path'])) $ta[] = $path['path']; if(isset($path['query'])) $ta = array_merge($ta, ["?", $path['query']]); if(isset($path['fragment'])) $ta = array_merge($ta, ["#", $path['fragment']]); print implode(" ", $ta) . "\n"; }
You have javascript disabled. You will not be able to edit any code.