Welcome to PHPMule.com
A blog site which I am posting to during my learning of the popular programming language PHP. Feel free to leave comments!
-
PHP - Using strlen() To Test String Length
This is a very useful function if you wanted to validate your visitor’s input on a web form. You could use this function to test out the length of their email address. The mininum length of an email address is six characters.
To test out the string we would use an If function along with the strlen() to find out if the string is more than six characters:
if (strlen($emailaddress) < 6) {
echo ‘Your email address is not valid’;
exit;
}
We could use this function on other input fields if we wanted to and it’s one useful measure against your visitors from sending spam. You can also limit the size using this function as well:
if(strlen($forename) > 30 {
echo ‘Your forename is too long’;
exit;
}
It should be in your best interest to implement these features in your forms because of security. There are other functions as well which validate user data which I will go through in another blog post!
(Post created on Tuesday, April 14th 09 at 13:45)
-
Calendar
| M | T | W | T | F | S | S |
|---|---|---|---|---|---|---|
| « Jun | ||||||
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 | ||||
Archives
Recent Articles
- PHP - Rounding Off Numbers
- PHP - Single vs Double Quotation Marks
- PHP - Loading Files Into Your PHP Script By Using require() and include()
- PHP - Replacing Strings With Other Strings
- PHP - Finding Strings Within Strings
- PHP - Using strlen() To Test String Length
- PHP - Using The explode() Function
- PHP - Changing The String Case
- PHP - The nl2br() Function
- PHP - Trimming Strings
Links
Categories
- PHP (22)
- Uncategorized (1)


