title: PHP preg_replace url get parameters in string
body: <p>Thanks to @s.d.a.p.e I've come a step close but I'm not quite there yet.</p>
  
  <p>What I'm trying to do is replace all instances of a string in a block of text.  I want to replace something like this:</p>
  
  <pre><code>user is ?user_id=34&amp;first_name=Ralph so is ?user_id=1 also
  </code></pre>
  
  <p>With this:</p>
  
  <pre><code>user is /user/34/ so is /user/1/ also
  </code></pre>
  
  <p>Here is the preg_replace code I'm using:</p>
  
  <pre><code>$pattern = '#\?user_id=([0-9]+)#';
  $replace = '/user/$1/';
  echo preg_replace($pattern,$replace,$string);
  </code></pre>
  
  <p>With that pattern I end up with this:</p>
  
  <pre><code>user is /user/34/&amp;first_name=Ralph so is /user/1/ also
  </code></pre>
  
  <p>Thanks again.</p>