<?

function is_urlsafe($str)
{
    
$safe_chars preg_match_all("/[a-zA-Z:\-_%0-9\/]/s"$str$matches);
    if (
$safe_chars != strlen($str))
        return 
false;

    return 
true;
}
function 
proper_urlencode($url)
{
    
$parts explode('/'$url);
    
$ret ="";
    while (
count($parts))
    {
        
$p array_shift($parts);
        if (!
is_urlsafe($p))
            
$p urlencode($p);
        
$ret .= $p;
        if (
count($parts))
            
$ret .= "/";
    }
    return 
substr($ret,0,strlen($ret));
}

if (
$_REQUEST["url"])
    print 
proper_urlencode($_REQUEST["url"]);
?>
<h1>fuck</h1>
<form method="post"><input type="text" name="url" size="80" /><input type="submit"/></form>