<?php
$url = 'http://m...content-available-to-author-only...l.com/my doc with more white spaces.doc';
$rurl = "";
if(isset($purl['scheme'])){ $rurl .= $purl['scheme'] . "://";
}
if(isset($purl['host'], $purl['path'])){ }
if($rurl === ""){
$rurl = $url;#error parsing error/invalid url?
}
echo $rurl;
PD9waHAKCiR1cmwgPSAnaHR0cDovL20uLi5jb250ZW50LWF2YWlsYWJsZS10by1hdXRob3Itb25seS4uLmwuY29tL215IGRvYyB3aXRoIG1vcmUgd2hpdGUgc3BhY2VzLmRvYyc7CiRwdXJsID0gcGFyc2VfdXJsKCR1cmwpOwokcnVybCA9ICIiOwppZihpc3NldCgkcHVybFsnc2NoZW1lJ10pKXsKICAgICRydXJsIC49ICRwdXJsWydzY2hlbWUnXSAuICI6Ly8iOwp9CmlmKGlzc2V0KCRwdXJsWydob3N0J10sICRwdXJsWydwYXRoJ10pKXsKICAgICRydXJsIC49ICRwdXJsWydob3N0J10gLiByYXd1cmxlbmNvZGUoJHB1cmxbJ3BhdGgnXSk7Cn0KaWYoJHJ1cmwgPT09ICIiKXsKICAgICRydXJsID0gJHVybDsjZXJyb3IgcGFyc2luZyBlcnJvci9pbnZhbGlkIHVybD8KfQplY2hvICRydXJsOw==