title: What is the best way to change matched words by one other in a file?
body: <p>I'm on a website project and administrators are able to create categories. When they do make them the name of the category is added to the database.<br>
  In the PHP file that processes the form used to create categories, I create a directory with the given name in the specific directory of my host, which at this time looks like:</p>
  
  <pre><code>exec('mkdir /homezx/user/website/categories/' . $_POST['name']);
  </code></pre>
  
  <p>It works fine, but now I'd like to copy a template from a resource folder to this new created directory (would be the index of it) and I know how to do it.</p>
  
  <pre><code>exec('cp .../templates/index.php /.../categories/' . $_POST['name'] . '/index.php');
  </code></pre>
  
  <p>The problem is I want to craft this template so it can fit the folder where it is placed.<br>
  In the template file, I've replace all the parts that will be different from one to one index with the string '%name%'.</p>
  
  <p>What could be the best way to copy this file in a created folder, after having changed all the '%name%' by a given name (e.g. in the title tag)?</p>