Posted By

scopefragger on 09/02/09


Tagged

count validate limit characters varable


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

umang_nine
scopefragger


Count Varable character lengh


 / 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.

  1. $varable = 'thisisatest';
  2. echo strlen($varable); // 11
  3.  
  4. $varable = '1234567';
  5. echo strlen($varable); // 7
  6. ?>
  7.  
  8.  
  9. //Nof for an 'if' example
  10. if(strlen($username)>8){$validate=='fail'}
  11. else
  12. {$validate=='pass'}

Report this snippet  

You need to login to post a comment.