SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    strlen for integers

    Hi,

    My variable $items (integer) can be any number between 1 and several hundred. I want to get a variable $digits indicating how many digits long $items is. At the moment, I'm doing this:
    PHP Code:
    $digits intval(strlen(strval($items))); 
    Other than doing
    PHP Code:
    $digits $items 1
    and similar things, is there another way that I'm missing?

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    strlen() will cast the argument to a string on its own, and always returns an integer, so just strlen($items) is sufficient.

  3. #3
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Wonderful. Cheers.


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
  •