Skip to content

Instantly share code, notes, and snippets.

@aramk
Created February 23, 2011 02:12
Show Gist options
  • Save aramk/839856 to your computer and use it in GitHub Desktop.
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.
<?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