So after working thirteen hours in a row I came home and thought of a handy function to bandaid some legacy code that returns a url with double slashes after the TLD. I realize this is a worse solution than fixing the code in question, but my regex-fu could use work so I though I’d do a little exploring. motel6 sparked my imagination and deserves full credit for my work below. Here’s what I came up with:
<?php
$url = remove_url_slashes('http://www.killallhumans.com//?robots_eating=hobos&passion=361', 'killallhumans');
function remove_url_slashes($url=”,$domain=”) {
if(empty($url))
return false;
if(empty($domain))
$domain = 'killallhumans';
$pattern = "/($domain)(.*?)(\/+)/ie";
return preg_replace($pattern, "'\\1\\2/'", $url);?>
}