1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

explode question

Discussion in 'PHP' started by emptyinside, Oct 12, 2007.

  1. #1
    Hy,

    I have and explode issue.

    I need to brake a string by more than one separators:

    EX: $vars = "var1/var2-var3/var4-var5-var6/var7"

    from this i need do get every var so explode("/",$vars) or explode ("-",$vars) just wouldn't do it.

    Many thanks
     
    emptyinside, Oct 12, 2007 IP
  2. mikebrad0927

    mikebrad0927 Peon

    Messages:
    266
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    can you use str_replace?
     
    mikebrad0927, Oct 12, 2007 IP
  3. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #3
    I agree. DO something like this:

    
    
    $vars = "var1/var2-var3/var4-var5-var6/var7";
    
    $formattedVars = str_replace('-','/',$vars);
    
    $array = explode('/',$formattedVars);
    
    //or into a single statement
    $array = explode('/',str_replace('-','/',$vars));
    
    
    PHP:
     
    jestep, Oct 12, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    You can also use preg_split()
    
    $chunks = preg_split('/[\/-]/', $vars);
    
    PHP:
     
    nico_swd, Oct 12, 2007 IP
  5. emptyinside

    emptyinside Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    never thought of that :), stupid me.

    many thanks.
     
    emptyinside, Oct 13, 2007 IP