title: Recursive strings replacement with PHP
body: <p>For a project I'm working on, I have a base URI with placeholders and I want to generate all the possible combinations from an array of possible values for each placeholder using PHP.</p>
  
  <p>More concretely:</p>
  
  <pre><code>&lt;?php
  $uri = "foo/bar?foo=%foo%&amp;bar=%bar%";
  
  $placeholders = array(
    '%foo%' =&gt; array('a', 'b'),
    '%bar%' =&gt; array('c', 'd'),
    // ...
  );
  </code></pre>
  
  <p>I'd like ending up having the following array:</p>
  
  <pre><code>array(4) {
    [0]=&gt;
    string(23) "foo/bar?foo=a&amp;bar=c"
    [1]=&gt;
    string(23) "foo/bar?foo=a&amp;bar=d"
    [2]=&gt;
    string(19) "foo/bar?foo=b&amp;bar=c"
    [3]=&gt;
    string(19) "foo/bar?foo=b&amp;bar=d"
  }
  </code></pre>
  
  <p>Not to mention I should be able to add more placeholders to generate more computed uris, of course, so the solution should work recursively.</p>
  
  <p>I might be overtired these days, but I'm getting stuck at achieving this simply, and I'm sure there's a simple way, perhaps even with builtin PHP functions… </p>
  
  <p>Hints? Any help much appreciated.</p>