Skip to content

Instantly share code, notes, and snippets.

@davidcroda
Created August 30, 2013 13:48
Show Gist options
  • Save davidcroda/6390033 to your computer and use it in GitHub Desktop.
Save davidcroda/6390033 to your computer and use it in GitHub Desktop.
<?php
$parsed = parse_url($url);
if(isset($parsed['scheme'])) {
$scheme = $parsed['scheme'];
} else {
$scheme = "http";
}
$path = substr($parsed['path'],1);
$parts = explode("/",$path);
foreach($parts as $k=>$part) {
$parts[$k] = urlencode(urldecode($part));
}
$url = "$scheme://{$parsed['host']}/".implode("/",$parts);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment