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.
- If you want to add
-
Should be at the end - If you want to add
\
, then it is necessary to save it from any other\
- 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
Post a Comment