My code to create an article spinner in PHP EASY

Discussion in 'PHP & Perl' started by Autom8r, Nov 2, 2009.

  1. Autom8r

    Autom8r Registered Member

    Joined:
    Aug 25, 2009
    Messages:
    76
    Likes Received:
    63
    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!
     
    • Thanks Thanks x 1
  2. _Austin

    _Austin Junior Member

    Joined:
    Apr 9, 2009
    Messages:
    147
    Likes Received:
    39
  3. Autom8r

    Autom8r Registered Member

    Joined:
    Aug 25, 2009
    Messages:
    76
    Likes Received:
    63
    Ahh now I see that.. sorry, misplaced post.
     
  4. kikou

    kikou Junior Member Premium Member

    Joined:
    Feb 23, 2008
    Messages:
    106
    Likes Received:
    66
    I wanted to do something like that. Thanks for the code.