Posted By

flatearthcomms on 02/13/15


Tagged

form php web fileupload


Versions (?)

translate non alphanumeric characters from file name into underscores


 / Published in: PHP
 

URL: http://stackoverflow.com/questions/1725104/reg-exp-wanted-for-replacing-all-non-alphanumeric-chars-with-underscores

Translate non alphanumeric characters into an underscore. Doesn't create double underscores if there's two spaces in a row. Also turns name to lowercase. Use with trim to avoid spaces at front or end.

  1. $filename=trim($_FILES['pdf']['name']);
  2. $name = preg_replace('/[^a-z0-9.]+/', '_', strtolower($filename));

Report this snippet  

You need to login to post a comment.