i want to delete first 5 lines in a text file

Discussion in 'PHP' started by brae2009, May 13, 2012.

  1. #1
    hello
    iam new in php

    i want to reed first 5 lines in text file

    then i want to delete first 5 lines in a text file "1.txt"

    i tried multi codes before

    i want to make a iframe from first 5 lines in the text then delete them and update the file



    <?php 
    $myFile = "1.txt";
    $lines = file($myFile);//file in to an array
     { 
    print "<iframe width=300 height=260 src=" . $line[1] . "></iframe><br />\n"; 
    print "<iframe width=300 height=260 src=" . $line[2] . "></iframe><br />\n"; 
    print "<iframe width=300 height=260 src=" . $line[3] . "></iframe><br />\n"; 
     }
    
    $File = "1.txt"; 
     $Handle = fopen($File, 'w');
    delete($Handle, $lines[1]);
    delete($Handle, $lines[2]);
    delete($Handle, $lines[3]); 
     fclose($Handle); 
    
     ?>
    
    Code (markup):
     
    brae2009, May 13, 2012 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,899
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #2
    loop through and any lines after #5 get added to a new string, then overwrite the old file with the new string.
     
    sarahk, May 13, 2012 IP
  3. PK-Host

    PK-Host Guest

    Messages:
    109
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #3
    <?php
    $myFile = "1.txt";
    $lines = file($myFile);//file in to an array
    print "<iframe width=300 height=260 src=" . $lines[0] . "></iframe><br />\n";
    print "<iframe width=300 height=260 src=" . $lines[1] . "></iframe><br />\n";
    print "<iframe width=300 height=260 src=" . $lines[2] . "></iframe><br />\n";
    print "<iframe width=300 height=260 src=" . $lines[3] . "></iframe><br />\n";
    print "<iframe width=300 height=260 src=" . $lines[4] . "></iframe><br />\n"; 
    
    $i = 0;
    $content = "";
    do {    
        $content .= $lines[$i] . "\n";
    } while ($i > 4);
    
    $Handle = fopen($myFile, 'w');
    fwrite($Handle, $content);
    fclose($Handle); 
    ?>
    PHP:
    That should work for you.
     
    PK-Host, May 14, 2012 IP