pioneerx01 Posted February 18, 2011 Share Posted February 18, 2011 In my form people are being asked for name which gets entered into database. How do I take my "$_POST[name]" and remove all characters but A-Z and a-z. I do not want ~`!@#$%^&*()_-+={[}]|\"':;?/>.<, there at all or numbers for that matter. I have been paying with stripslashes and strip_tags but they don't fully cut it Thanks Quote Link to comment https://forums.phpfreaks.com/topic/228072-removing-all-unwanter-charachers-but-a-z-and-a-z/ Share on other sites More sharing options...
requinix Posted February 18, 2011 Share Posted February 18, 2011 One of the things a regular expression is good at: saying "everything except". preg_replace('/[^a-zA-Z]/', "", $text) Quote Link to comment https://forums.phpfreaks.com/topic/228072-removing-all-unwanter-charachers-but-a-z-and-a-z/#findComment-1176086 Share on other sites More sharing options...
wigpip Posted February 18, 2011 Share Posted February 18, 2011 i agree i love the 'except rule: ^', or you could do it this way with the 'i' for case insensitive, whichever $string = 'me.]'; $nw = preg_replace("/[^a-z]/i",'',$string); echo $nw; Quote Link to comment https://forums.phpfreaks.com/topic/228072-removing-all-unwanter-charachers-but-a-z-and-a-z/#findComment-1176087 Share on other sites More sharing options...
pioneerx01 Posted February 18, 2011 Author Share Posted February 18, 2011 Fantastic. Works like a charm. I have added a space because when someone enters First Last Name I get FirstLastName preg_replace('/[^a-zA-Z ]/', "", $fn1) Thank you all. This site rocks! Quote Link to comment https://forums.phpfreaks.com/topic/228072-removing-all-unwanter-charachers-but-a-z-and-a-z/#findComment-1176089 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.