Count Varable character lengh

/ Published in: PHP
Save to your folder(s)

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.

Copy this code and paste it in your HTML
  1. $varable = 'thisisatest';
  2. echo strlen($varable); // 11
  4. $varable = '1234567';
  5. echo strlen($varable); // 7
  6. ?>
  9. //Nof for an 'if' example
  10. if(strlen($username)>8){$validate=='fail'}
  11. else
  12. {$validate=='pass'}


Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.