title: How to replace all occurences of specific words with given replacements in a given string in PHP
body: <p>I want users to write HTML in disguise and so to write a link, they just have to write the following:</p>
  <pre><code>#link webpage.php #linktoken #linktext Click here linktext# link#
  </code></pre>
  <p>This will be equivalent to writing the following HTML:</p>
  <pre><code>&lt;a href=&quot;webpage.php&quot;&gt;Click here&lt;/a&gt;
  </code></pre>
  <ul>
  <li>Here <code>#link</code> will be changed to <code>&lt;a href=&quot;</code></li>
  <li><code>#linktoken</code> will be changed to <code>&quot;&gt;</code></li>
  <li><code>#linktext</code> and <code>linktext#</code> will be changed to <code>&quot;&quot;</code></li>
  <li><code>link#</code> will be changed to <code>&lt;/a&gt;</code></li>
  <li>the text between <code>#link</code> and <code>#linktoken</code> will be preserved</li>
  </ul>
  <p>This will leave us with the following:</p>
  <pre><code>&lt;a href=&quot; webpage.php &quot;&gt;Click here&lt;/a&gt;
  </code></pre>
  <p>And lastly I want to remove the spaces before and after the word &quot;webpage.php&quot;. This will leave me with the desired result:</p>
  <pre><code>&lt;a href=&quot;webpage.php&quot;&gt;Click here&lt;/a&gt;
  </code></pre>
  <p>Any solution?</p>