title: Add string after some predefined string
body: <p>I have one file, eg: hello.txt with the following content in it</p>
  <p>Hi
  Nice</p>
  INSERT TEXT MARKER
  <p>I want to create a script that enters &quot;Hello World&quot; after ####INSERT TEXT MARKER####.</p>
  <p>I have used below code to do it.</p>
  <pre><code>&lt;?php
  function insert_into_file($file_path, $insert_marker, $text, $after = true) {
      $contents = file_get_contents($file_path);
      $new_contents = preg_replace($insert_marker, ($after) ? '$0' . $text : $text . '$0', $contents);
      return file_put_contents($file_path, $new_contents);
  }
  
  $file_path = &quot;hello.txt&quot;;
  $insert_marker = &quot;####INSERT TEXT MARKER####&quot;;
  $text = &quot;Hello World&quot;;
  
  $num_bytes = insert_into_file($file_path,$insert_marker,$text,true);
  
  if ($num_bytes === false) {
      echo &quot;Could not insert into file $file_path.&quot;;
  } else {
      echo &quot;Insert successful!&quot;;
  }
  ?&gt;
  </code></pre>
  <p>But my file goes empty.
  Please help!</p>