codrgii Posted May 29, 2011 Share Posted May 29, 2011 Using the preg_replace function, how can i enable the use of Latin a-b letters alongwith basic english a-z and without jeopardising security? just to be clear i would like to only allow Latin a-b characters and english a-z removing anything else if anyone is unsure what Latin a-b characters are then goto http://en.wikipedia.org/wiki/List_of_Unicode_characters Quote Link to comment Share on other sites More sharing options...
codrgii Posted May 29, 2011 Author Share Posted May 29, 2011 is it possible? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted May 29, 2011 Share Posted May 29, 2011 You mean something like this $str = '$#La souri$<<>-//s a été mangée par le chat '; $str = preg_replace('/[^\p{L}\s-]/u', '', $str); echo $str; //Outputs La souri-s a été mangée par le chat This is not my code. I found a similar question here http://stackoverflow.com/questions/3436746/help-with-preg-replace-and-special-chars Quote Link to comment Share on other sites More sharing options...
xyph Posted May 29, 2011 Share Posted May 29, 2011 [^\p{L}\p{M}\p{Z}\p{N}] Match a single character NOT present in the list below «[^\p{L}\p{M}\p{Z}\p{N}]» A character with the Unicode property “letter” (any kind of letter from any language) «\p{L}» A character with the Unicode property “mark” (a character intended to be combined with another character (e.g. accents, umlauts, enclosing boxes, etc.)) «\p{M}» A character with the Unicode property “separator” (any kind of whitespace or invisible separator) «\p{Z}» A character with the Unicode property “number” (any kind of numeric character in any script) «\p{N}» Created with RegexBuddy 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.