Alex Poole

Pragmatic PHP, MySQL, Marketing & Technology

Alex Poole header image 2

Simple PHP Article Spinner

April 27th, 2009 by alex

I was doing some SEO for an excellent site on Friday. Their on-page was excellent, and they had some desirable backlinks. One problem they did have though was duplicate content on their location-specific “doorway” pages - pages designed to rank for “Blue Widgets Ely”, “Blue Widgets Cambridge” etc

I proposed they at least “spun” the body copy on these pages. This approach gives you 100s or 1000s of semi-unique pieces of content for little more work than writing one. 

I’ve tested this technique on a “madlib” site with 5 million virtual “pages” and whilst Google gobbled them up for a while, it de-indexed most. Interestingly, though, it kept in the index hundreds of pages unique only due to their spun copy.  I believe therefore that if used sensitively, keeping in mind human readability and given sufficient options for the number of unique documents required, it still works.

To “fix” a page so that the same random options are used every time when that page is visited, use this near the top of the page:


<?php
mt_srand(crc32($_SERVER['REQUEST_URI'])));
?>

Here’s the function:
<?php

function Spin($txt){

$test = preg_match_all("#\{(.*?)\}#", $txt, $out);

if (!$test) return $txt;

$toFind = Array();
$toReplace = Array();

foreach($out[0] AS $id => $match){
$choices = explode(”|”, $out[1][$id]);
$toFind[]=$match;
$toReplace[]=trim($choices[rand(0, count($choices)-1)]);
}

return str_replace($toFind, $toReplace, $txt);
}

?>
You use it like this:
<?php
$text = "The {quick|slow|reasonably paced} {brown|green|blue|pink} {fox|goat|rat|camel}
 {jumped|walked|hopped} {over|past|under} the {lazy|tired|boring} {dog|cat|stoat}";
$count = 0;
while ($count++ < 100){
echo Spin($text);
echo "<br />";
}
?>

That’s it. Simple effective article spinning for free.

By the way, I’ve seen better and more efficient versions of this - I’m not pretending its the be-all and end-all, but it does the job.

What do you think of this technique? Have you tried it? Please share your findings!

Tags:   · · · · 22 Comments

Leave a Comment

22 responses so far ↓

  • [...] function to generate contextually similar, different, content. The original concept is here, but I have enhanced it a bit to better suit my [...]

  • Hi Alex,

    Just started my own blog (last Fri - so it’s a bit sparse / unfinished as yet!) and have added a post about this topic too. Hopefully you are happy with this (http://www.paul-norman.co.uk/2009/06/spin-text-for-seo/) and may find the alterations useful in future.

    Once again, great concept, thanks!

  • useful. You still need the jet spinner syntax though. the best way to get that is automatically, at autojetspinner.com - paste in your text, click a button, and bang - The {quick|fast|swift} {brown|russet|red} fox {jumped|leaped|vaulted} over the…

  • Cool bit of php that. It could be used in all kinds of apps in various ways. Will that code only spin one level deep though? What would need adding to be able to spin two levels deep?

  • Thank’s a lot guy ! ;)

  • Hi Alex,
    How would you modify your script to allow for nested spins ( such as {test | try { this | that }}? That would be great to have.

  • Hi Alex,

    Hope you are well and that you are gearing up for a fun new year! Just a quick one on this topic - someone asked me yesterday for a version of this code that allowed nested spin blocks, so I’ve added a second function that can do this on my blog post on the topic (http://www.paul-norman.co.uk/2009/06/spin-text-for-seo/) the code is a rush job, but it should do the trick…

  • Thanks fo this. Just about saved my bacon. If you are struggling with this code and the using the URL as a seed and getting an error then try this:

    srand(crc32($_SERVER['REQUEST_URI']));

    Hope that helps. Paul Norman’s site is down at the moment. I wanted to check his solution as well. Lots of uses for this :)

    YA!

  • This is just a long shot but I don’t suppose anyone knows if there is an auto - synonym replacement solution to auto spin existing content on the fly? Would need a DB of synonyms I would guess.

  • i bought a php article submitter script that doesn’t have a spinning capability. so i thought “what if i could change it so it can do spinning while submitting, just like SENuke, that’d be cool! but how do i do that?”, then this article made it possible for me. THANK YOU SO MUCH!

  • [...] I don’t have to explain to you the importance of avoiding duplicate content on your sites. There are a lot of PHP content spinners avaiable but I really like this one I found here. [...]

  • Did you even try the code yourself or just type it into a blog post? It just echos the $text var 100 times, never actually spinning anything lol.

    It’s hilarious that people are thanking you when the code doesn’t do anything.

  • People do thank the author because they’re clever enough to have replaced the original quotes of the article by real quotes in this line : $choices = explode(”|”, $out[1][$id]);

    Thanks alex !

  • Thanks for the info. But I have an question about this.
    How to make it work for blogspot? Is it possible for blogspot blog?

  • nope, blogspot does not allow you to run custom code. Sorry. Better and far more secure to host your own blog

  • Thanks so much for that spinner, i’ve been looking for a good spinning program and couldn’t find anything suitable for my needs. I like your very simple piece of code and will start from it. I will let you know when i add some functions and will post the php code. Cheers!

  • Thank you very much Alex. I like your script.

    Thanks

  • [...] auf dem blog von Paul Norman (link) zu finden, wobei sein script auf einem script von Alex Poole (link) basiert. Wie das script in aktion aussieht, könnt Ihr hier sehen: php artikelspinner. Den [...]

  • This gives me a good start on what I was after. I need to add nested spinning and tie it to a form with a preview, but I think this code is what I needed. Thanks.

  • Cheers. Check out Paul’s evolution of the script for nested spinning:

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

  • Great script! On a side note, would anyone have a php script that could compare 2 articles to determine uniqueness?