/ Published in: PHP
URL: http://www.scopesden.co.uk/code_get_feed.php?Content_ref=14
Sometimes counting the length of a variable is a necessity, such as when a new user registers. You may restrict a limit of 10 characters as a username or password, Using the following php function you can count the length of a variable.
In additionally I have provided an example ‘If’ statement that could be used in a username length validation.
Expand |
Embed | Plain Text
Comments
Subscribe to comments
You need to login to post a comment.

Actually you should use regular expression for username validation:
if (preg_match('/^[a-z]{8,}$/i', $username)) { echo 'OK'; } else { exit('Wrong username'); }true, however when typing this i was short of examples so username lengh validation was a nice friendly introduction to strlen. More to the point a good example of strlen would be the function that will be used in http://www.scopesden.co.uk/codegetfeed.php?Content_ref=14 to evaluate the size of the text feed and to manipulate the number of rows required so that 1, the page isnt epic huge for a single liner code and secondly so that a 200 line code isnt squeesed into a 1 row box ( there extreamaties but you get the point ). Other than that thogh i havent realy used strlen.
true, however when typing this i was short of examples so username lengh validation was a nice friendly introduction to strlen. More to the point a good example of strlen would be the function that will be used in http://www.scopesden.co.uk/codegetfeed.php?Content_ref=14 to evaluate the size of the text feed and to manipulate the number of rows required so that 1, the page isnt epic huge for a single liner code and secondly so that a 200 line code isnt squeesed into a 1 row box ( there extreamaties but you get the point ). Other than that thogh i havent realy used strlen.
If you're using PHP4, using strlen() will only work for non-multibyte encoded strings. If you have a multibyte encoding such as UTF-8, then mb_strlen() should be used, or a compatible function. Almost all the PHP4 string functions suffer from this problem.
nb: "Varable" is spelled variable.
Bucabay