PHP change whole line if a word exist in a line of .txt file
<p>I'm using <code>preg_replace</code> to search for a word match within a line of a text file. If it is found, I would like to replace the entire line.  My current problem is what I've tried thus far only replaces the exact word and not the entire line.</p>

<p><strong>PHP</strong></p>

<pre><code>  $database = "1.txt";
  $id = "OFFENSIVEWORD1";
  $str = file_get_contents($database);
  $str = preg_replace("/\b".$id."\b/","********",$str);
  $fp = fopen($database,'w');
  fwrite($fp,$str);
  fclose($fp); 
</code></pre>

<p><strong>1.TXT FILE</strong></p>

<pre><code>LOVING YOU MY FRIEND etc.
OFFENSIVEWORD1 YOU MY FRIEND etc.
OFFENSIVEWORD2 YOU MY FRIEND etc.
OFFENSIVEWORD3 YOU MY FRIEND etc.
</code></pre>

<p><strong>EXPECTED OUTPUT</strong></p>

<pre><code>LOVING YOU MY FRIEND etc.
********
OFFENSIVEWORD2 YOU MY FRIEND etc.
OFFENSIVEWORD3 YOU MY FRIEND etc.
</code></pre>

<p>Thanks.</p>
