My code to create an article spinner in PHP EASY

Autom8r

Registered Member
Joined
Aug 25, 2009
Messages
76
Reaction score
65
Hey all, I wanted to create my own {word1|word2|word3} style article spinner in .php, here's all it took:

PHP:
function SPIN() {
            preg_match_all('/{(.*?)}/',$_POST['tbox'],$spin);            
            $find = $spin[0];
            $replace = $spin[1];
            for($i=0;$i<count($find);$i++) {
                $sub = explode("|",$replace[$i]);
                $sub = $sub[rand(0,count($sub)-1)];                
                $_POST['tbox'] = str_replace($find[$i],$sub,$_POST['tbox']);
            }
            
            echo $_POST['tbox'];
        }

From the code above, you will want to put a textarea element on your page called "tbox", or change the code to reflect whatever your textarea element is called.

This is super simple and powerful, replaces all instances of {word1|word2|word3} with a random choice from within the squiggly brackets.

Cheers, hope you like it!
 
I wanted to do something like that. Thanks for the code.
 
Back
Top