How to replace/delete an entire line of text after matching a phrase in a textfile
<p>Basically I want PHP to open a config file, search for a string  and replace the entire line or until the next closing brackets...
The problem that I have in the code that I have created is that it finds  the string <code>define(\"DB_PASS\"</code> and is able to replace it... but then in the file there is an extra  <code>"password");</code> line... so i need it to be able to replace the entire line or either cut the rest to be able to delete it.</p>

<pre><code>$dbFile = 'dbconfig.php';
$String = "define(\"DB_PASS\", \"$password\");\n";
file_put_contents($dbFile, str_replace("\ndefine(\"DB_PASS\",", $String, file_get_contents($dbFile)));
</code></pre>

<p>dbconfig.php</p>

<pre><code>    &lt;?php
    // Database Constants
    define("DB_SERVER", "localhost");
    define("DB_USER", "admin");
    define("DB_NAME", "test");
    define("DB_PASS", "password");
?&gt;
</code></pre>

<p>my current script outputs like this
dbconfig.php</p>

<pre><code>      &lt;?php
        // Database Constants
        define("DB_SERVER", "localhost");
        define("DB_USER", "admin");
        define("DB_NAME", "test");
        define("DB_PASS", "NEW_password");
"password");
    ?&gt;
</code></pre>
