Top Left Text cha

Web & App Development

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...

$uploadChunks = pathinfo($_FILES['upload']['name']);
$upload = preg_replace("![^a-z0-9]+!i", "-", $uploadChunks['filename']).'.'.$uploadChunks['extension'];

Add comment


Security code
Refresh

  • No comments found

Leave your comments

Post comment as a guest

0
Your comments are subjected to administrator's moderation.
X