FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


want to delete first 5 lines in a text file





brae2009
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



Code:
<?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);

 ?>
badai
you're lucky i'm low on points

Code:
<?php
$file_to_read = "1.txt";
//read 5 lines
$line = array();
$file = fopen($file_to_read, "r") or exit("Unable to open ".$file_to_read);
while(!feof($file)) {
   $line[] = fgets($file);
}
fclose($file);
if (count($line) >= 5)
   $count = 4;
else
   $count = count($line);
for ($i = 0; $i <= $count; $i++)
   /*
   echo "<iframe width=\"300\" height=\"260\" src=\"".$line[$i]."\"></iframe><br />\n";
   why the f you want to use iframe?
   frame/iframe/frameset is used to embed another document/url within the current HTML document.
   do you want to dump the whole content of 5 files/url, or just 5 lines from a file?
   or all the lines actually files'  name/urls? but it will break because of the line break at the end of line
   learn html first before you jump to php
   see http://www.w3schools.com/tags/tag_iframe.asp
   */
   echo nl2br($line[$i]);
   
//if less than 5 lines and still want to output 5 iframe....
if ($i < 5)
   for ($j = $i; $j < 5; $j++)
      //dump blank iframe
      //echo "<iframe width=\"300\" height=\"260\"></iframe><br />\n";
      echo "<br />file only content ".count($line)." lines";

//delete first 5 lines, empty file (0 byte) if less than 6 lines in source file
$file_to_write = "t";   //make sure this file didn't exist
$file = fopen($file_to_write, "w") or exit("Unable to open ".$file_to_write);
for ($i = 5; $i < count($line); $i++)
   fwrite($file, $line[$i]);
fclose($file);

unlink($file_to_read);
rename($file_to_write, $file_to_read);
   
?>
brae2009
Many thanks that really help thank you
Related topics
users online, using php and text file
Random Quotes Services for anyone - 1 Frih$ for 170+ quotes
Visual Basic Tutorial - File I/O in VB: Text Files
styling text string read from plain text file
Register for 18 Frih$ Re-registering allowed!!!! First 5 !
Reading from text file into Flash
Deleting certain lines from text file
HELP, reading text file from USB drive in visual basic
download a text-file daily
how to add a text file in mp3 data using java ?
Delete An "undeletable" File
English Dictionary in text file or sql database
Perl how to encrypt your text file contents with Perl
edit option not available for a text file
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.