sh0wtym3 Posted November 11, 2008 Share Posted November 11, 2008 Hey All, This a snippet from my upload script. At the moment it replaces spaces with "_" and makes the title lowercase. $file = str_replace(' ', '_', $_POST['title']); $file = strtolower($file); I also have a Javascript code that restricts the user from typing certain characters, such as apostrophes. Apparently Javascript doesn't work on all browsers as a user just uploaded a file, with a title that has an apostrophe in it, which created all sorts of problems for me. (I cannot delete or rename the file in my ftp) I added 3 more lines that will hopefully prevent this from happening in the future: $file = str_replace(' ', '_', $_POST['title']); $file = strtolower($file); $pattern="*^$%&()#@!'"; $replace=""; ereg_replace($file,$pattern,$replace); But it doesn't seem to work? If you need to see more of my code just let me know. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
sh0wtym3 Posted November 11, 2008 Author Share Posted November 11, 2008 Sorry looks like somebody else asked a similar question in another thread, and the solution (which worked for me as well) is: I would recommend not using ereg, as of PHP6, it will not be supported in the core by default (I think it will only be an extension). You should use preg instead. Here is a good starter thread for that. You can also read about PCRE regex here. $str = 'testing 123...'; $str = preg_replace('#[^a-z0-9]#', '', $str); echo $str; Ouput: testing123 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.