SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: PHP and length

Hybrid View

  1. #1
    SitePoint Wizard jumpthru's Avatar
    Join Date
    Apr 2000
    Location
    Los Angeles, California
    Posts
    1,008
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What is the function to count the number of charecters in a variable? Also what is the function to see if a variable exists? Thanks!

    ------------------
    Nate - nate@jumpthru.com
    ICQ 70944023
    http://www.jumpthru.com - Unbelievable Website design!
    http://www.jumpthru.com/christian - Learn, live, love, jesus christ...

  2. #2
    SitePoint Member
    Join Date
    May 2000
    Location
    Ilfracombe,Devon,UK
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Function to count characters in a string variable is

    "strlen($textvariable)"

    To check for existance of a variable, you only have to enclose it's name within an

    "if($do_i_exist)"

    statement, as a non-existant string equates to "" or 0. The alternative is to use the

    "isset($do_i_exist)"

    function. The latter is obviously the only option if "0" or "" are possible valid values for an existing variable.

  3. #3
    SitePoint Zealot
    Join Date
    Nov 1999
    Location
    Manhattan!
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When using text variables (from user input) I usually do:

    if(strlen(trim($my_var))) {

    // do something

    }

    To check that they have not just entered spaces...

    Christian


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
  •