translate non alphanumeric characters from file name into underscores


/ Published in: PHP
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  1. $filename=trim($_FILES['pdf']['name']);
  2. $name = preg_replace('/[^a-z0-9.]+/', '_', strtolower($filename));

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.