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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.