<?php
function clean($string) {
   $string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
   return preg_replace('~[^\w %\[\].()%\\:@&/-]~', '', $string); // Removes special chars.
}

$d =  clean("this was http://nice readlly n'ice 'test for@me to") ;
echo $d;
?>