php spintax script

Discussion in 'PHP' started by mbaldwin, Oct 11, 2011.

  1. #1
    Hi,
    I am looking for a php script for parsing out spintax. Or at least directions on where I should start for making my own.

    Thanks,
    Michael
     
    mbaldwin, Oct 11, 2011 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
  3. Usama Ejaz

    Usama Ejaz Active Member

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    56
    Digital Goods:
    1
    #3
    function spin($var){
    $spun = "";

    $words = explode("{",$var);
    foreach ($words as $word)
    {
    $words = explode("}",$word);
    foreach ($words as $word)
    {
    $words = explode("|",$word);
    $word = $words[array_rand($words, 1)];
    $spun .= $word." ";
    }
    }

    return $spun;
    }

    USAGE:

    echo spin("This is {my|your|yours|the} text that came after being spun!");
     
    Usama Ejaz, Jun 1, 2014 IP