title: How can I replace each URL in a string with another unique URL?
body: <p>I have the following:</p>
  
  <pre><code>$reg[0] = '`&lt;a(\s[^&gt;]*)href="([^"]*)"([^&gt;]*)&gt;`si';
  $reg[1] = '`&lt;a(\s[^&gt;]*)href="([^"]*)"([^&gt;]*)&gt;`si';
  $replace[0] = '&lt;a$1href="http://www.yahoo.com"$3&gt;';
  $replace[1] = '&lt;a$1href="http://www.live.com"$3&gt;';
  $string = 'Test &lt;a href="http://www.google.com"&gt;Google!!&lt;/a&gt;Test &lt;a href="http://www.google.com"&gt;Google!!2&lt;/a&gt;Test';
  echo preg_replace($reg, $replace, $string);
  </code></pre>
  
  <p>Which results in:</p>
  
  <pre><code>Test &lt;a href="http://www.live.com"&gt;Google!!&lt;/a&gt;Test &lt;a href="http://www.live.com"&gt;Google!!2&lt;/a&gt;Test
  </code></pre>
  
  <p>I'm looking to end up with (the difference being in the first link):</p>
  
  <pre><code>Test &lt;a href="http://www.yahoo.com"&gt;Google!!&lt;/a&gt;Test &lt;a href="http://www.live.com"&gt;Google!!2&lt;/a&gt;Test
  </code></pre>
  
  <p>The idea is to replace each URL within a link within a string with a unique other URL. It's for a newsletter system where I want to track what people have clicked on, so the URL will be a "fake" URL which they will be redirected to the real URL after the click is recorded.</p>