Skip to content

Instantly share code, notes, and snippets.

@aramk
Created February 23, 2011 02:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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