Search code examples
phplineerase

How can I erase a line from a ini file using php?


Does someone know how can I find a line in a ini file and erase using php?

fopen etc..?


Solution

  • Use this :

    $content = '';
    // iterate over each line of the ini file
    foreach(file('your.ini') as $line) {
         // if the line doesn't start with YOURKEY ...
         if(!preg_match('~^YOURKEY~', $str)) {
             // add it to output
             $content .= $line;
         }
    }
    file_put_contents('your.ini', $content);