php - Restrict characters used in a string -


How can I restrict the string of characters in the whitelist?

  // "I understand how to do this; BAD" $ str = ban ($ str, "0- 9a-z."); // "I understand that this is",  

Does PHP have an inbuilt function which is close to something? I can not prepare a regular expression for this: (

OK, if you change the bus Use characters you want (note, you can add any letters with some cavities.

  1. If you want to add - Should be at the end
  2. If you want to add \ , then it is necessary to save it from any other \
  3. if You can see the / , [ or ] \ )

This allows some characters and filters the rest:

  $ str = Preg_replace ('/ [^ a-za-z.] /', '', $ Str);  

If you want to reject any string that contains any characters Which does not match:

  if (preg_match ('/ [^ A-Za-z.], /', $ Str)) {// rejected string}  < / Pre> 

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -