SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Wibblesticks Gryff's Avatar
    Join Date
    Oct 2001
    Location
    Asgard
    Posts
    442
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    minimum variable lengths

    how do i check the length of a variable?
    and how do i use it in an if statement?
    thanks for any help as usual

  2. #2
    SitePoint Wizard johnn's Avatar
    Join Date
    Mar 2001
    Location
    Southern California, USA
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you want to see if a variable has a length of 10:
    if (strlen ($variable) == 10)
    {
    //yes it is
    }

  3. #3
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just a small side-note: strip the whitespace at the beginning and end of the variable, too, if you're trying to limit public user input. Example:

    PHP Code:
      if (strlen(trim($text)) == 10) {
        
    // do stuff
      



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •