Learn How to Create a Profitable Online Business in 30 Days or Less Working from Home

PHP Text Spinner

You know what text/article spinners are and what they are used for. Usually article spinning is used to spin articles and submit “unique” spun copies to different article directories and other websites. But what if you wanted to spin the text automatically on your website?

Recently I needed such functionality on one of my websites and as a result I’ve created a PHP function that would spin text provided in a spinner syntax. The function turned out to be so simple that I’ve decided to post it here should anyone need it.

As it turns out there are even commercial PHP spinners out there that cost a nice buck – you get to use this one for free! The function is a simple spinner that just spits out a spun text and supports nested syntax:

function spin($s){
	preg_match('#\{(.+?)\}#is',$s,$m);
	if(empty($m)) return $s;

	$t = $m[1];

	if(strpos($t,'{')!==false){
		$t = substr($t, strpos($t,'{') + 1);
	}

	$parts = explode("|", $t);
	$s = preg_replace("+\{".preg_quote($t)."\}+is", $parts[array_rand($parts)], $s, 1);

	return spin($s);
}

//Example:
echo spin('{This|Here} is {some|a {little|wee} bit of} {example|sample} text.');

Enjoy!

Filed under Internet Marketing · Tagged with , , , , ,

Comments

2 Responses to “PHP Text Spinner”
  1. Lee says:

    I’m going to try it and see. Thanks so much for sharing it with your readers.

  2. Simple Seo says:

    Wow, that is very clean.
    Shortest spin code I have ever seen by far.

    Thanks!

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!