|
What are the most common PHP validation functions and techniques?
The "ctype" functions
.
- ctype = character type
- ctype_alpha(), ctype_digit(), ctype_alnum()
- Very fast
stripos()
.
- Finds position of a string in a string
- Return value of 0 = 1st position
- Returns FALSE if not found
- Very fast
- Has problems with multi-byte strings
- Use strpos() for case sensitive
preg_match()
.
- Intelligent match using a regular expression
- Use "u" modifier to support UTF-8
- Performance considerations involved
- Do not use in a lengthy loop
Validation by lookup
.
- Often associated with HTML <select> tags
- Validate against a list of known values
- Lookup source could be array or database
- DO NOT use user input directly!
|
|