Incredibly basic spinner php code

bsmaat

New member
Jun 19, 2007
58
1
0
Alright guys,
I was pretty bored this evening and decided to procrastinate a little bit by studying a bit of php and trying to make my own little spinner. Now, I hadn't intended to post it here and it's pretty crappy, but who knows, maybe the code will be of some use to someone here learning. I might try to add to it over the next few days and see what I can come up with...

PHP:
<html>
<body>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Article to Spin:<br> <textarea name="spin" cols=50 rows=30><?php if(!empty($_POST['spin'])) { echo $_POST['spin']; } else echo "Spinning text here..."; ?></textarea>
<br>
<input type="submit">
</form>
</body>
</html>


<?php

function spin($temp) {

  $final = '';
  $tempsize = strlen($temp);
  for($i=0; $i < strlen($temp); $i++) {
    #echo substr($temp, $i);
    
    if (substr($temp, $i,1) == '{') { 
       $pos1 = $i+1;
       
       $part1 = substr($temp, 0, $i);       

       while(!(substr($temp, $i,1) == '}')) {
         $i++;
       }

       $pos2 = $i-1;
       $tmpstr = substr($temp, $pos1, $pos2-$pos1+1);

       $buff = explode('|', $tmpstr);
       $temp = substr($temp, $i+1);
       $final = $final . $part1 . $buff[rand(0, count($buff)-1)];

       $i=0;
     }
  }      
  $final = $final.$temp;


  return $final;
   

}

if (!empty($_POST['spin'])) {

   $spin = $_POST['spin'];
   echo spin($spin);
}

?>

Oh, if i've coded something by going against convention, let me know. In the mean time.

Something's you could add/ideas I was thinking about (ive never used a spinner myself so I dont know what's available):
- construct all possible combinations then see if there is somewhere on the web where we can get a % of grammar correctness or something
- maybe a different bracket, like [ ] where the words inside the brackets are checked up against an online/local thesaurus

Anyway, hope it helps somebody...

Just noticed it's pretty hard to read in the code tags. Oh well...
 


Hey, really...I applaud you trying to contribute and all, but...

Nigga Plz.


Laterly,in every thread i see an asshat stupid comment from you.
Keep your stupid shit to STS, and don't mess with people who contribute code.
doesn't fit your standards ?
GTFO

/rant
 
Laterly,in every thread i see an asshat stupid comment from you.
Keep your stupid shit to STS, and don't mess with people who contribute code.
doesn't fit your standards ?
GTFO

/rant
Nah, Galacon is pretty cool bro; But yeah, comments like these should stick to the STS section, Galacon. :]