PHP Help..

Discussion in 'PHP' started by BAM78, Aug 11, 2008.

  1. #1
    I have a script that outputs my data like this

    YH1H-BJ-YD35-0Y12Y8-102Y0Y

    Each output is random

    How can I make that look like this

    YH1H/-BJ-/YD35/-0Y12/Y8-/102Y/0Y
     
    BAM78, Aug 11, 2008 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,905
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #2
    There's probably a regular expression that will do it easily but you can always use explode('-',$str) to get the bits and then just rebuild it from the array.
     
    sarahk, Aug 11, 2008 IP
  3. BAM78

    BAM78 Peon

    Messages:
    115
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I need the / in the same spot
    and all the outputted data is the same length
     
    BAM78, Aug 11, 2008 IP
  4. zac439

    zac439 Notable Member

    Messages:
    3,074
    Likes Received:
    214
    Best Answers:
    0
    Trophy Points:
    260
    #4
    We are going to need more information. One would think that all dashes have a slash preceding them or superceding them.

    Was this a mistake or intentional:

    (I don't see a dash- in which case if it was intentional we need to know how we find out where slashes go before we can manipulate the original string)
     
    zac439, Aug 11, 2008 IP
  5. BAM78

    BAM78 Peon

    Messages:
    115
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    YH1H/-BJ-/YD35/-0Y12/Y8-/102Y/0Y
    was intentional

    I need the / in the same spots as this example for all the output data

    example of output data
    AH1H-BJ-YD35-0Y12Y8-102Y0Y
    BH1H-BJ-HD35-0Y1HY8-102H0U


    example of what I need
    AH1H/-BJ-/YD35/-0Y12/Y8-/102Y/0Y
    BH1H/-BJ-/HD35/-0Y1H/Y8-/102H/0U
     
    BAM78, Aug 12, 2008 IP
  6. mallorcahp

    mallorcahp Peon

    Messages:
    141
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    if the "/" is always in the same place you could use substr ...

     
    mallorcahp, Aug 12, 2008 IP
  7. is0is0

    is0is0 Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Your dashes are random and not following a pattern therefore I cannot help you unless you want to do regex.
     
    is0is0, Aug 12, 2008 IP
  8. zac439

    zac439 Notable Member

    Messages:
    3,074
    Likes Received:
    214
    Best Answers:
    0
    Trophy Points:
    260
    #8
    Exactly what I tried to tell him :rolleyes:
     
    zac439, Aug 12, 2008 IP
  9. sarahk

    sarahk iTamer Staff

    Messages:
    28,905
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #9
    A better way to build the string is to use implode() on the array generated by explode.
     
    sarahk, Aug 12, 2008 IP