title: PHP replace string with values from array
body: <p>I have a string such as:</p>
  
  <pre><code>   Hello &lt;%First Name%&gt; &lt;%Last Name%&gt; welcome
  </code></pre>
  
  <p>and I have a array</p>
  
  <pre><code> [0] =&gt; Array
      (
          [First Name] =&gt; John
          [Last Name] =&gt; Smith
      )
  </code></pre>
  
  <p>What I need to do is take the string and replace the words in &lt;% with the actual text from the array</p>
  
  <p>So my output would be </p>
  
  <pre><code>   Hello John Smith welcome
  </code></pre>
  
  <p>Im not sure how to accomplish this but I cant even seem to replace it with regular text </p>
  
  <pre><code>$test = str_replace("&lt;%.*%&gt;","test",$textData['text']);
  </code></pre>
  
  <p>Sorry I should of mentioned that the array keys may vary as well as the <code>&lt;%First Name%&gt;</code></p>
  
  <p>so it could even be <code>&lt;%city%&gt;</code> and the array can be <code>city=&gt;New York</code></p>