PHP Spintax Class

A while back I had published a simple code snippet for a PHP Spintax Function on CodeDevelopr. This post is the new improved version 2 as the old version did not perform well on large strings. We are now using a nice PHP class as well but it can be wrapped into a simple spintax function if you prefer.

What is Spintax?

The term spintax is a contraction of spinning + syntax.

Spintax is the format or syntax that is used by various software spinners and websites that create or use spun articles or content.

What this means is that you can create multiple versions of text from a single string of text.
This is done by randomly returning one of the text items in between the Pipes in a Spintax string. This is what a simple Spintax string looks like


For example if this spintax code {Hello|Howdy|Hola} was ran through our PHP Spintax Class below, it would randomly return one of these Hello or Howdy or Hola.

As you can see this can be really useful to create multiple versions of text from a single text string.

PHP Spintax Class

PHP Spintax Example Usage

Example usage of our Spintax PHP Class

Basic Spintax

Spintax string: {Hello|Howdy|Hola} to you, {Mr.|Mrs.|Ms.} {Smith|Williams|Davis}!

Spintax Output: Howdy to you, Mrs. Davis!

Nested Spintax

You can also Nest Spintax inside of Spintax, several levels deep. Here is an example of a Nested Spintax string


If you find this Spintax Class/function useful, please share the page on Social Media and leave Comments below.