I used this specifically to combat a problem with file downloads - when the user uploads them and adds special characters like '#', '?', etc. Just a PHP preg_replace function, which uses RegEx...
$url = preg_replace("![^a-z0-9]+!i", "-", $url);
excl!hash## !@#$%^&().pdf becomes excl-hash-.pdf
You can replace the dash with nothing like below and it will just smash everything around the special characters together...
$url = preg_replace("![^a-z0-9]+!i", "-", $url);
excl!hash## !@#$%^&()d.pdf becomes exclhash.pdf
For me it was a little more complicated as it was a file upload that needed changed. So I used the code below...
Comments