Supprimer une chaine dans un fichier php

zamouranou -  
 zamouranou -
Bonjour,

svppp je veux supprimer juste une chaine mais tjr je trouve le fichier vide !!!

<?php
$fp = fopen ("vls.cfg", "r");

$texte=file_get_contents("vls.cfg");
$texte=str_replace($chaine ,'',$texte);
$fp = fopen ("vls.cfg", "w+");
fclose ($fp);
?>

2 réponses

  1. jisisv Messages postés 3678 Statut Modérateur 936
     
    Cela fonctionnera mieux comme ceci:
    johand@osiris: johand@osiris: ~/src/CCM/php $ cat vls.cfg 
    kdgfnboljb fighn  
    BLAH12345BLAH 
    jbdsvjcfjfenvjfdevhnrevjhnb 
    àçç!èèBLAH 
    johand@osiris: ~/src/CCM/php $ cat text.php 
    <?php 
    $chaine="BLAH"; 
    $file="vls.cfg"; 
    
    $texte = file_get_contents($file); 
    $texte = str_replace($chaine ,'',$texte); 
    
    $fp = fopen($file, "w") or die("Could not open $file"); 
    fwrite($fp, $texte); 
    fclose ($fp); 
    ?> 
    johand@osiris: ~/src/CCM/php $ php text.php 
     johand@osiris: ~/src/CCM/php $ cat vls.cfg 
    kdgfnboljb fighn  
    12345 
    jbdsvjcfjfenvjfdevhnrevjhnb 
    àçç!èè


    Gates gave ^H sold you the windows.
    GNU gave us the whole house.(Alexandrin)
    0
  2. zamouranou
     
    ca marche pas pour moi !! j'ai des erreur au niveau code et aussi je détecte que le fichier a eu des modification et ops l'orsque j'ouvre le fichier rien n'est changé
    voici la chaine que je veux la supprimé
    BEGIN"223"
    Name = "test5"
    FileName = "/home/flux/SD/hd_h264_1.ts"
    # Type = "Mpeg2-TS"
    END

    BEGIN "Channels"
    out223 = "network"
    END

    BEGIN "out223"
    DstHost = "225.22.15.19"
    DstPort = "5001"
    TTL = "2"
    Type = "multicast"
    END

    BEGIN "LaunchOnStartUp"

    #flux223 = "start test5 out223 local1 --loop"

    END
    #################################
    0