How to remove a certain piece of text from a file (not by line number)?

    1 answer 1

    Because the question is very vague, so will the answer ...

    $file = file_get_contents('/url/'); //url - пусть к вашему файлу $toReplace = 'это надо заменить'; $replace = ''; //пустота... $file = str_replace($toReplace, $replace, $file); // заменяем 'это надо заменить' на пустоту, т.е. удаляем 


    There are suspicions that the TC thinks that by updating this variable we are updating the contents of the file ...
    In general, just in case here:

     // ложим уже измененную строку в этот же файл... file_put_contents(/url/, $file); //url - путь к вашему файлу... 
    • it is not necessary to replace, namely, to remove - shol
    • 2
      Well, replace $ replace with "" <br> learn to think ... - Zowie
    • does not work, tried and more than once - shol
    • The code in the studio, badly tried means - Zowie
    • $ t = file_get_contents ($ file); $ r = "; str_replace ($ toreplace, $ r, $ t); - shol