Free php spinner!

A while ago a friend of mine, an SEO guy, told me about the concept of ‘spinning’ content. Basically the idea is to get many articles out of one article, by adding replacement words or phrases to the one article you write. Then, every time you refresh the page, the same – but different – article is displayed. It’s mostly a way to confuse search engines into thinking you have more content than you do, but sometimes it’s useful; E.g. if you have a summary of an article which is ripped straight from the main article, you might get a duplicate content penalty from Google every time it looks at your site.

It’s always struck me as odd than nobody seems to have written anything (freely available anyway. $97? Bugger that!) for such a simple task, so I thought what the heck, I’ve got an hour or two, why don’t I write it myself? So I did, and here it is;

function spin($text) {

//While there's pairs of square brackets, spin whats inside of them
while (!(strpos($text,'[') === FALSE) && !(strpos($text,']') === FALSE)) {

//Find the first '['
$leftb = strpos($text,'[');

//Find the first ']'
$rightb = strpos($text,']');

//Split the string up, then (psudo)randomise the item chosen
$spintext = split(',',substr($text,$leftb+1,$rightb-$leftb-1));
$spinselect = trim($spintext[mt_rand(0,count($spintext)-1)]);

//Get the whole string to replace including the brackets
$brackettext = substr($text,$leftb,($rightb-$leftb)+1);

//Replace the [blah,blah2] with whatever item is chosen
$text = str_replace($brackettext,$spinselect,$text);

}

//return the block of modified text
return $text;

}

You can see the code in action on this demo. I think this is probably worth a beer, even though I haven’t made a wordpress or joomla addon for it yet, but it should be pretty simple to adapt (for WordPress anyway). I might make one later on, even if I’m still completely sober.

4 thoughts on “Free php spinner!

  1. Hi Kythin,

    Just came across this post when I was updating my spinner code yesterday and thought it might interest you. I also didn’t enjoy the fact that people charged ~$100 for a small block of simple php code so I try to share my versions wherever they might stop people paying that ridiculous fee or give them inspiration with their own versions. I have two versions of this, one using regexps that acts like yours (with slightly different syntax {{spin|me}} – as I thought I may want single braces and commas in my spin arguments) and the second that I added yesterday (due to request) running off strpos that allows nested spin blocks (e.g. {{some text|some {{different|fun}} text}}). Hopefully these might just provide you with some ideas for your version / plugins.

    Source: http://www.paul-norman.co.uk/2009/06/spin-text-for-seo/

  2. Yeah, sure, use the code at will! I wrote mine with the intention to help others.

    (And sorry for the late response – been skiing, and returned to find my DNS all screwed up… fixed now!)

Leave a Reply