Jump to content

filtering


codrgii

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/237736-filtering/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/237736-filtering/#findComment-1221887
Share on other sites

 

 

[^\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

Link to comment
https://forums.phpfreaks.com/topic/237736-filtering/#findComment-1222007
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.