SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    398
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    exploding data problem

    im trying to explode dynamic data, but thing is, im not sure how many things im going to have to explode. so say i had to explode this

    $data = "data1:data2:data3:data4";

    i would have to use this

    list($data_1, $data_2, $data_3, $data_4) = explode(":", $data);


    but seeing as its dynamic, $data could also be

    $data = "data1:data2";

    or

    $data = "data1:data2:data3:data4:data5";



    so what im trying to figure out, is how do i change the explode list(), depending on how many things need to be exploded. is there some sort of if or while statement

  2. #2
    SitePoint Evangelist barbara1712's Avatar
    Join Date
    Apr 2007
    Location
    India
    Posts
    508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    use array instead of list like

    PHP Code:
    $data "data1:data2:data3:data4:data5";
    $dataArray=explode(":",$data);
    foreach(
    $dataArray as $v)
    {
    echo 
    $v ."<br>";

    Barbara

  3. #3
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    398
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    okay but if i needed each one of those to be seperated into variables and have something i can echo seperatly like

    echo $data_1;
    echo $data_2;
    echo $data_3;

  4. #4
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    398
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nevermind i got it, thanks


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
  •