Replace string in text file using PHP

前端 未结 3 1239
耶瑟儿~
耶瑟儿~ 2020-11-29 02:52

I need to open a text file and replace a string. I need this

Old String: 
New String: 

        
3条回答
  •  迷失自我
    2020-11-29 03:26

    Does this work:

    $msgid = $_GET['msgid'];
    
    $oldMessage = '';
    
    $deletedFormat = '';
    
    //read the entire string
    $str=file_get_contents('msghistory.txt');
    
    //replace something in the file string - this is a VERY simple example
    $str=str_replace($oldMessage, $deletedFormat,$str);
    
    //write the entire string
    file_put_contents('msghistory.txt', $str);
    

提交回复
热议问题