title: PHP Spintax Processor
body: <p>I've been using the recurisve SpinTax processor as seen <a href="http://www.codedevelopr.com/articles/php-spintax-function/" rel="noreferrer">here</a>, and it works just fine for smaller strings. However, it begins to run out of memory when the string goes beyond 20KB, and it's becoming a problem. </p>
  
  <p>If I have a string like this: </p>
  
  <pre><code>{Hello|Howdy|Hola} to you, {Mr.|Mrs.|Ms.} {Smith|Williams|Austin}!
  </code></pre>
  
  <p>and I want to have random combinations of the words put together, and <strong>not</strong> use the technique as seen in the link above (recursing through the string until there are no more words in curly-braces), how should I do it? </p>
  
  <p>I was thinking about something like this: </p>
  
  <pre><code>$array = explode(' ', $string);
  foreach ($array as $k=&gt;$v) {
          if ($v[0] == '{') {
                  $n_array = explode('|', $v);
                  $array[$k] = str_replace(array('{', '}'), '', $n_array[array_rand($n_array)]);
          }
  }
  echo implode(' ', $array);
  </code></pre>
  
  <p>But it falls apart when there are spaces in-between the options for the spintax. <code>RegEx</code> seems to be the solution here, but I have no idea how to implement it <strong>and</strong> have much more efficient performance. </p>
  
  <p>Thanks!</p>