Created
February 23, 2011 02:12
-
-
Save aramk/839856 to your computer and use it in GitHub Desktop.
Simple URL Standardization that takes a user input URL and attempts to standardize it. If no URL scheme is given, defaults to http, also appends a forward slash if needed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function url_std($url) { | |
extract(parse_url($url)); | |
if ($scheme == '') { | |
$scheme = 'http'; | |
} | |
$url = $scheme . "://" . $host . $path; | |
// Append a forward slash if needed | |
if ( !preg_match('|/$|', $url) ) { | |
$url .= '/'; | |
} | |
return $url; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment