<?php
class SeoMixer
{
    public $input;
    public $output;
    public $limit = 1;
    private $braces = array("{", "}");
    private $delimiter = "|";
    
    function __construct($input)
    {
        $this->input = $input;
    }
    
    function mixAll()
    {
        $this->output = $this->input;
        while (strpos($this->output, $this->braces['1']) !== false)
        {
            $closed = strpos($this->output, $this->braces['1']);
            $substr = substr($this->output, 0, $closed + 1);
            $from = strrpos($substr, $this->braces['0']);
            $substr = substr($substr, $from);
            $_substr = $this->mixText($substr);
            $this->output = str_replace($substr, $_substr, $this->output);
            $substr = "";
            $_substr = "";
        }
        return;
    }
    
    function mixText($text)
    {
        $text = str_ireplace($this->braces, "", $text);
        $elements = explode($this->delimiter, $text);
        return $elements[array_rand($elements)];
    }
    function mix()
    {
        $this->mixAll();
        return $this->output;
    }
}
?>
