SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Guru
    Join Date
    Oct 2001
    Location
    USA
    Posts
    764
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unsplitting a split

    OK so I put numbers together into a variable...separated by ":"

    Such as 5:10:15

    My question is...how do I pull them back apart? Into an array or something.

  2. #2
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Parry Sound, ON
    Posts
    725
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $arr explode(":"$var); 

  3. #3
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $string = '5:10:15';

    $stringArr = explode(':',$string);//$stringArr[0]=5,[1]=10,[2]=15 [[explodes string and generates an array

    $string = implode(':',$stringArr);//back to '5:10:15' [[implodes an array and generates a string

  4. #4
    SitePoint Guru
    Join Date
    Oct 2001
    Location
    USA
    Posts
    764
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I need to put this into a while statement though.

  5. #5
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Parry Sound, ON
    Posts
    725
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you be a little more vague?

  6. #6
    SitePoint Guru
    Join Date
    Oct 2001
    Location
    USA
    Posts
    764
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok well you know the While( part...I need to do something every time a single variable is pulled out of the the mess 5:10:15...so grab 5 then do something grab 10 then do something then grab 15 do something and stop

  7. #7
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $string '5:10:15';

    $stringArr explode(':',$string);
    foreach(
    $stringArr as $key=>$value)
    {
      echo 
    $value.'<br>';//gonna go to each element one by one


  8. #8
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Parry Sound, ON
    Posts
    725
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
     $arr explode(":"$var);
    foreach(
    $arr as $num)
    {
       
    //do stuff


  9. #9
    SitePoint Guru
    Join Date
    Oct 2001
    Location
    USA
    Posts
    764
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys


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
  •