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. Quote Link to comment 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_]. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.