- 1). Paste the following PHP code to use as a template for your spinner project:
<?php
function Spin($txt){
$test = preg_match_all("#\{(.*?)\}#", $txt, $out);
if (!$test) return $txt;
$toFind = Array();
$toReplace = Array();
foreach($out[0] AS $id => $match){
$choices = explode("|", $out[1][$id]);
$toFind[]=$match;
$toReplace[]=trim($choices[rand(0, count($choices)-1)]);
}
return str_replace($toFind, $toReplace, $txt);
}
?> - 2). Add the following code below to run your spinner project. The code will create two functions: the spin function and the replacement line for the first instance of a string:
<?php
$text = "The {fast|timid| reluctantly slow} {red|green|purple|pink} {fox|sheep|moose|camel}
{jumped|walked|hopped} {over|past|under} the {sleepy|exhausted|boring} {dog|cat|goat}";
$count = 0;
while ($count++ < 100){
echo Spin($text);
echo "<br />";
}
?>
This code will produce various funny yet beneficial spin combinations for your subject in terms of SEO, such as:
The fast red fox walked over the sleepy dog
The timid green sheep walked under the exhausted goat
The reluctantly slow pink moose hopped over the boring cat - 3). Paste the code below to keep your PHP spinner project nested in its designated spot:
$string = '{{A {{common|basic}} example|An uncomplicated scenario|The {{plain|trivial|elementary|rudimentary}} case|My {{analysis|invest{{igative|igation}}}} case}} to illustrate the {{problem|issue}}';
echo '<p>';
for($i = 1; $i <= 5; $i++)
{
echo Spinner::detect($string, false).'<br />';
// or Spinner::nested($string, false).'<br />';
}
echo '</p>';
SHARE