Let's say I have an HTML page with a text field that ask the user to enter a word. Then, I use the $_POST[]
variable in my PHP script to play with the variable and do some stuff. My page and my PHP scripts would work using the UTF-8 encoding so anything can be entered by the user.
What I would like to know, it's how can I make sure that all characters contained in the word entered by the user are part of a predefined list of characters?
For example, the list would contain the characters 0 to 9, a to z, A to Z, but also some other characters like ü, ù, ô, é, à, ẑ and so on. What I don't want, it's characters like from the Russian alphabet like а, з, б, у, etc and other kinds of exotic characters.
I could use regular expression, but is it the most suitable solution? Isn't too slow? What about an array with all the characters? Is it me or it sounds very slow to loop through each character of a word and also loop through the array of accepted characters and test each combination.
Do you know a good solution?
Thanks.