Page 1 sur 1

Modifier un fichier TXT (ajout texte à chaque début de ligne

Posté : 21 mars 2005, 00:48
par Laurent S.
Bonjour,

J'aurais besoin d'un coup de pouce :
J'ai un fichier .TXT avec un listing du genre (extrait) :

03groupsia.htm
03sia.htm
03siagroup.htm
03simaplanning.htm
04016_001Bis.jpg
05 livret saa.doc
05ddaf.htm
06ddaf.htm
10contact.JPG
156contact.JPG
160modernisation2.doc
162action.doc
162hand.doc
162INTERVIEW.doc
162MODERNISATION.doc
162PARTENAIRE.doc
162STRATEGIE.doc
162VIE.doc

Et je voudrais gràce à un script PHP rajouter en chaque début de ligne un texte bien précis (ici : "http://www.truc.com/" ):

http://www.truc.com/03groupsia.htm
http://www.truc.com/03sia.htm
http://www.truc.com/03siagroup.htm

etc...

Comment faire ???

Merci d'avance ! ... c'est un question de vie ou de mort pour moi ! ;)

Posté : 21 mars 2005, 00:58
par ouckileou
une idée comme ça

utiliser la fonction "file" (http://fr2.php.net/function.file)
elle lit un fichier et renvoie un tableau, dont chaque cellule contient une ligne du fichier

tu peux donc rajouter ton texte :
$texteArajouter = "abcde";
for ($i=0;i<tab.length();i++) {
   $tab[i] = $texteArajouter.$tab(i];
}
ou qqchose comme ça

Posté : 21 mars 2005, 11:09
par tanky
ca devrait faire un truc dans ce style:
$txtAjout = "http://www.truc.com/";

// lecture du fichier
$nouveauContenu = "";
$fichierLu = fopen("fichier.txt","r");
while (!feof($fichierLu)) 
{
    $ligne = fgets($fichierLu, 4096);
    $nouveauContenu .= $txtAjout.$ligne;
}
fclose($fichierLu);

// ecriture deu nouveau fichier
$fichierEcrit = fopen("fichier.txt","w");
fputs($fichierEcrit, $nouveauContenu);
fclose($fichierEcrit);