PHP EXPLODE Problem

Discussion in 'PHP' started by scottlpool2003, Feb 14, 2011.

  1. #1
    Hi guys, having trouble splitting some items up in PHP. The list below is a small extract of over 1000 items.

    ITEM1¬a/item1.html
    ITEM2¬a/item2.html
    ITEM3¬a/item3.html

    I added the ¬ as an identifier where to split I need them to split like:

    $item
    $url

    So far I managed:

    $url = file_get_html('pasteitems.php');
    $pieces = explode(".html", $url);
    
    foreach ($pieces as $piece) {
    echo "$piece<br>";	
    }
    PHP:
    That split them into:

    ITEM1¬a/item1
    ITEM2¬a/item2
    ITEM3¬a/item3

    But I'm stuck how to have them as 2 variables

    Please help!



    And then enter into a db
     
    scottlpool2003, Feb 14, 2011 IP
  2. TimK

    TimK Peon

    Messages:
    51
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    $url = file_get_html('pasteitems.php');
    $pieces = explode(".html", $url);
    $final = preg_split("/^ITEM[0-9]/", $piece);
    foreach ($pieces as $piece) {
    echo "$piece<br>"; 
    }
    
    PHP:
    $final[0] = ITEM1
    $final[1] = a/item1

    Should work. Untested and in a rush. Let me know how it goes.
     
    TimK, Feb 14, 2011 IP
  3. nikhilmohan

    nikhilmohan Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I agree With TimK ....
     
    nikhilmohan, Feb 18, 2011 IP