URGENT! Help With Explode > Implode

Discussion in 'PHP' started by mob4u1, Dec 4, 2009.

  1. #1
    I need to open a file containing page names and create a form to set the order in which they are to be shown.

    The first PHP code shown produces the form using the variables in the pageorder.php file (name/page) then using the form overwrite the file with updates using implode...

    pageorder.php file:
    home/index|about/about|contact/contact
    PHP:
    CODE:
    
    if(!$_POST['sumbit']) {
    				
    $filename = "../includes/pageorder.php"; $handle = fopen($filename, "r");
    $Content = fread($handle, filesize($filename)); fclose($handle);
    			
    echo '<form method="post" action="">';
    
    $pagearray = explode("|", $Content);
    foreach( $pagearray as $pagedetails){
    list($name, $page) = explode("/", $pagedetails);
    echo '<p><input readonly style="background:#fff;border:0;" type="text" name="page" value="'.$page.'"/>' . "\n";
    echo ' > <input type="text" name="name" value="'.$name.'" /></p>' . "\n";
    echo '<input type="text" name="namepage" value=""/>' . "\n";
    }
    
    echo '<p><textarea name="pageorder" cols="50" rows="10">'. $Content .'</textarea></p>';
    echo '<p><input class="button" type="submit" name="sumbit" value="submit"/> ';
    echo '<a class="button" href="index.php">cancel</a></p>';
    echo '</form>';
    
    } else {
    $Content = $_POST['pageorder'];
    $reffilename2 = "../includes/pageorder.php"; $ourFileName2 = $reffilename2;
    $ourFileHandle2 = fopen($ourFileName2, 'w') or die("can't create PHP file");
    $ourFileData2 = $Content;
    fwrite($ourFileHandle2, $ourFileData2);
    fclose($ourFileHandle2);
    }
    
    PHP:
    i have tried using these:
    $pieces = array($name,$page);	
    $glue_pipe = implode("|", $pieces); $glue_slash = implode("/", $pieces);
    for($i = 0; $i < count($pieces); $i++){
    echo "Piece #$i = $pieces[$i] <br />";
    }
    echo "Glued with Spaces = $glue_pipe <br />";
    echo "Glued with Dashes = $glue_slash";
    
    $arr = array($name,$page); $separated = implode("/", $arr); echo $separated;
    $separated1 = implode("|", array($separated)); echo $separated1;
    
    
    PHP:
    but neither work...

    this is very urgent!!! thanks!!!
     
    mob4u1, Dec 4, 2009 IP
  2. xrvel

    xrvel Notable Member

    Messages:
    918
    Likes Received:
    30
    Best Answers:
    2
    Trophy Points:
    225
    #2
    I am sorry but i can't understand your question. Can you clarify what do you want? Maybe with some image for guide or something like that :)
     
    xrvel, Dec 18, 2009 IP
  3. elias_sorensen

    elias_sorensen Well-Known Member

    Messages:
    852
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    110
    #3
    If you want to split multiple parts into an array (I assume it is what you want?) then you'd probably want to use the split() function which is able of regex splitting into arrays.
     
    elias_sorensen, Jan 5, 2010 IP
  4. mob4u1

    mob4u1 Well-Known Member

    Messages:
    951
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    110
    #4
    already sorted this issue, thanks, mods please close thread...
     
    mob4u1, Jan 5, 2010 IP