Text Spinner & Similarity Check in PHP

A very small script that will spin the text and count similarity between two spun text.


class Spintax { public function process($text) { return preg_replace_callback( '/\{(((?>[^\{\}]+)|(?R))*)\}/x',
array($this, 'replace'),
$text
);
}
public function replace($text)
{
$text = $this->process($text[1]);
$parts = explode('|', $text);
return $parts[array_rand($parts)];
}
}
/* EXAMPLE USAGE */
$spintax = new Spintax();
$string = '{Ways To Get|Learn To Get|Suggestions|Where To Get|Inexpensive|How To Attract|Learn How To Get|Affordable|Obtaining|Ideas|Tips|Tips To Get} More Repeat Customers
Coldness, numbness and loss of hand coordination are ';

$spin1 = $spintax->process($string);
$spin2 = $spintax->process($string);

/* NESTED SPINNING EXAMPLE */
echo $spin1."

";
echo $spin2."

";

$sim = similar_text($spin1, $spin2, $perc);
echo "similarity: $sim ($perc %)\n";


Leave a Reply

Your email address will not be published. Required fields are marked *