Stooney Posted March 17, 2008 Share Posted March 17, 2008 I rarely use regex so I don't know much about em. Basically I need to take an uploaded file and rename it to only contain alpha numeric characters. What's the easiest way to replace all non-alpha numeric characters with an underscore? So... Jim's Document.txt would become Jim_s_Document.txt The file extension does not need to have characters replaced if it matters. Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/96496-uploaded-filenames/ Share on other sites More sharing options...
effigy Posted March 17, 2008 Share Posted March 17, 2008 $str = preg_replace('/\W/', '_', $str); \W is shorthand for [^A-Za-z0-9_]. Link to comment https://forums.phpfreaks.com/topic/96496-uploaded-filenames/#findComment-494138 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.