Back To Normal
Click Here To Subscribe Via Email

Subscribe To Our E-Mail Newsletter

Friday, August 22, 2014

PHP Spintax Class (with Nested Spinning)

Couch ModePrint It

Hi there. I am sharing a simple and easy to use PHP Spintax class which supports nested spinning too.
You can use this code in your web apps.

It has been written by Jason Davis (


 * Spintax - A helper class to process Spintax strings.
 * @name Spintax
 * @author Jason Davis -
class Spintax
    public function process($text)
        return preg_replace_callback(
            array($this, 'replace'),
    public function replace($text)
        $text = $this->process($text[1]);
        $parts = explode('|', $text);
        return $parts[array_rand($parts)];

The Usage:

$message="Hi {buddy|friend|dear}, this message has been spun";
$spintax = new Spintax();
echo $spintax->process($message);

Let me know if you have any thoughts ;)