SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist Jhorra's Avatar
    Join Date
    Sep 2004
    Location
    Phoenix, Az
    Posts
    551
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Break apart a variable

    I think this could be simple, I have just never done it before. I have a variable which is someone's SSN. The dashes are there which is good I think, so it would be 111-11-1111. What I want to do is only take the last 6 digits of it and get rid of the dash.

  2. #2
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Try the following:

    PHP Code:
    $ssn '111-11-1111';
    $part substr(str_replace('-'''$ssn), -6); 
    Yours, Erik.
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  3. #3
    It's been real... Forbes's Avatar
    Join Date
    Dec 2004
    Location
    Yorkshire, England
    Posts
    676
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try:
    PHP Code:
    $part substr(str_replace('-'''$ssn), (count($ssn) - 6), count($ssn)); 
    It's more obvious what's going on. But it's a fair bit longer.

    That's the great thing about PHP; there are many different ways of doing the same thing...


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
  •