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.

Split String up

Discussion in 'PHP' started by rederick, Nov 8, 2006.

  1. #1
    Hi,

    I need to split up a string like this

    A99B99C99E99F05G05H02N99P04Q99R99S02T10U04U05V99W03Z03

    into

    A99,B99,C99,E99,F05,G05,H02,N99,P04,Q99,R99,S02,T10,U04,U05,V99,W03,Z03


    So Every Third Character I need to break up with some type of delimiter.

    Is there an Easy way to do this?

    Thank you
     
    rederick, Nov 8, 2006 IP
  2. clancey

    clancey Peon

    Messages:
    1,099
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    0
    #2
    This will do the trick:

    
    $text = 'A99B99C99E99F05G05H02N99P04Q99R99S02T10U04U05V99W03Z03';
    $deliminator = "-";
    $text = preg_replace( '/[A-Z0-9]{3}/i', "$0$deliminator", $text);
    $text = preg_replace( "/$deliminator$/", "", $text);
    
    PHP:
    The second statement removes trailing deliminators.
     
    clancey, Nov 8, 2006 IP
  3. rederick

    rederick Peon

    Messages:
    128
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you Clancey!!

    Works Perfectly.

    :D
     
    rederick, Nov 8, 2006 IP