title: Unspin text in php from spun text on sentence level
body: <p>I need to neatly output spun text in a php page.
  I already have the prespun text in {hi|hello|greetings} format.
  I have a php code that i found elsewhere, but it does not output the spun text on sentence level, where two {{ come. 
  Here is the code that needs fixing. </p>
  
  <pre><code>&lt;?php
  
  function spinText($text){
      $test = preg_match_all("#\{(.*?)\}#", $text, $out);
  
      if (!$test) return $text;
  
      $toFind = Array();
      $toReplace = Array();
  
      foreach($out[0] AS $id =&gt; $match){
      $choices = explode("|", $out[1][$id]);
      $toFind[]=$match;
      $toReplace[]=trim($choices[rand(0, count($choices)-1)]);
      }
  
      return str_replace($toFind, $toReplace, $text);
  }
  
  echo spinText("{Hello|Hi|Greetings}!");;
  
  ?&gt;
  </code></pre>
  
  <p>The output will be randomly chose word: Hello OR Hi OR Greetings.</p>
  
  <p>However, if there is a sentence level spinning, the output is messed up.
  E.g.:</p>
  
  <pre><code>{{hello|hi}.{how're|how are} you|{How's|How is} it going}
  </code></pre>
  
  <p>The output is </p>
  
  <pre><code>{hello.how're you|How is it going}
  </code></pre>
  
  <p>As you can see the text has not been spun completely.</p>
  
  <p>Thank you</p>