function send_header () {
print "<!doctype html public \"-//w3c//dtd html 4.0 transitional//en\">";
print "<html>";
print "<head>";
print " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">";
print "<META HTTP-EQU=\"pragma\" CONTENT=\"no-cache\"> ";
print "<META HTTP-EQU=\"Cache-Control\" CONTENT=\"no-cache\"> ";
print "<META HTTP-EQUIV=\"Expires\" CONTENT=\"Tue, 20 Aug 1996 14:25:27 GMT\"> ";
print " <meta name=\"Generator\" content=\"Microsoft Word 97\">";
print " <meta name=\"Template\" content=\"C:\PROGRAM FILES\MICROSOFT OFFICE\OFFICE\html.dot\">";
print " <meta name=\"GENERATOR\" content=\"Mozilla/4.7 [en] (Win98; I) [Netscape]\">";
print " <title>Compte Cafetière de l'équipe maintenance</title>";
print "</head>";
print "<body link=\"#0000FF\" vlink=\"#800080\">";
}
function send_footder () {
print "</body>";
print "</html>";
}
Function InsertInFile($FileName, $line, $InsertString) {
$fp = fopen("MyTmpFile.txt", 'w');
$Tableau=file($FileName);
$l=0;
while ($l<$line) {
fwrite($fp, $Tableau[$l]);
$l++;
}
fwrite($fp, $InsertString);
while ($l<count($Tableau)) {
fwrite($fp, $Tableau[$l]);
$l++;
}
fclose($fp);)
unlink($FileName);
rename("MyTmpFile.txt", $FileName)
}
send_header();
// On va insérer 2 lignes (truc + bidule) dans le fichier test.txt après la ligne 3
InsertInFile("test.txt", 3, "Truc\r\nBidule\r\n"); // \r\n pour windows sur unix \n devrait suffire
send_footder();
En espérant que ça pourra t'aider.Function InsertInFile($FileName, $line, $InsertString, $from="h") {
$fp = fopen("MyTmpFile.txt", 'w');
$Tableau=file($FileName);
$l=0;
switch ($from) {
case "b":
case "B":
$limit=count($Tableau)-$line;
break;
default:
case "h":
case "H":
$limit=$line;
break;
}
while ($l<$limit) {
fwrite($fp, $Tableau[$l]);
$l++;
}
fwrite($fp, $InsertString);
while ($l<count($Tableau)) {
fwrite($fp, $Tableau[$l]);
$l++;
}
fclose($fp);
unlink($FileName);
rename("MyTmpFile.txt", $FileName);
}
Pour mettre 3 lignes avant la fin :InsertInFile("test.txt", 3, "Truc\r\nBidule\r\n", "B");Code : Tout sélectionner
<?php function send_header () {
print "<!doctype html public \"-//w3c//dtd html 4.0 transitional//en\">";
print "<html>";
print "<head>";
print " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">";
print "<META HTTP-EQU=\"pragma\" CONTENT=\"no-cache\"> ";
print "<META HTTP-EQU=\"Cache-Control\" CONTENT=\"no-cache\"> ";
print "<META HTTP-EQUIV=\"Expires\" CONTENT=\"Tue, 20 Aug 1996 14:25:27 GMT\"> ";
print " <meta name=\"Generator\" content=\"Microsoft Word 97\">";
print " <meta name=\"Template\" content=\"C:\PROGRAM FILES\MICROSOFT OFFICE\OFFICE\html.dot\">";
print " <meta name=\"GENERATOR\" content=\"Mozilla/4.7 [en] (Win98; I) [Netscape]\">";
print " <title>Compte Cafetière de l'équipe maintenance</title>";
print "</head>";
print "<body link=\"#0000FF\" vlink=\"#800080\">";
}
function send_footder () {
print "</body>";
print "</html>";
}
Function InsertInFile($FileName, $line, $InsertString, $from="h") {
$fp = fopen("MyTmpFile.txt", 'w');
$Tableau=file($FileName);
$l=0;
switch ($from) {
case "b":
case "B":
$limit=count($Tableau)-$line;
break;
default:
case "h":
case "H":
$limit=$line;
break;
}
while ($l<$limit) {
fwrite($fp, $Tableau[$l]);
$l++;
}
fwrite($fp, $InsertString);
while ($l<count($Tableau)) {
fwrite($fp, $Tableau[$l]);
$l++;
}
fclose($fp);
unlink($FileName);
rename("MyTmpFile.txt", $FileName);
}
send_header();
InsertInFile("test.txt", 10, "truc\r\nbidule\r\n", "B");
send_footder();
Code : Tout sélectionner
InsertInFile("test.txt", 10, "truc\r\nbidule\r\n", "B");
Code : Tout sélectionner
InsertInFile("test.txt", 10, $data, "B");
Code : Tout sélectionner
InsertInFile("test.txt", 10, $_POST['data'], "B");