I realize that this is a little late but thought you might have some interest in spinning and truncating your article for web usage so that you don't cut it off in the middle of a sentence or paragraph and that you will get a good uniqueness of over 30% on a consistent basis without having to redo your articles every week.
Should someone come up with changes or a better way to handle this please do...Otherwise I hope you like what I put together and found..
<?php
/
$pass : The spinned text to un-spin
/
function Spin($pass){
$mytext = $pass;
while(inStr("}",$mytext)){
$rbracket = strpos($mytext,"}",0);
$tString = substr($mytext,0,$rbracket);
$tStringToken = explode("{",$tString);
$tStringCount = count($tStringToken) - 1;
$tString = $tStringToken[$tStringCount];
$tStringToken = explode("|",$tString);
$tStringCount = count($tStringToken) - 1;
$i = rand(0,$tStringCount);
$replace = $tStringToken[$i];
$tString = "{".$tString."}";
$mytext = str_replaceFirst($tString,$replace,$mytext);
}
return $mytext;
}
function str_replaceFirst($s,$r,$str){
$l = strlen($str);
$a = strpos($str,$s);
$b = $a + strlen($s);
$temp = substr($str,0,$a) . $r . substr($str,$b,($l-$b));
return $temp;
}
function inStr($needle, $haystack){
return @strpos($haystack, $needle) !== false;
}
/
$string : The original string to truncate
$limit : The number words to truncate to, may well be over a little due to it ending on the paragraph boundary and not the word boundary.
/
function myTruncate($string, $limit) {
// return with no change if string is shorter than $limit
$WC = str_word_count($string);
$NWC = 0;
$ReturnString = null;
if($WC <= $limit) return $string;
while( $NWC < $limit ){
// Find percent of total vs $limit
$PerC = $limit / $WC;
// Find First Paragraph ending
$Para = stripos($string,"\r\n");
if( $Para ){
$NewString = substr($string,0,$Para+2);
$string = str_ireplace($NewString,"",$string);
$string = ltrim($string);
$NWC += str_word_count($NewString);
}
if( str_word_count($NewString) > 10 ){
// Add in your own formatting for the paragraphs
$ReturnString .= "<p style='line-height:normal'><span style='font-size:12.0pt;font-family:\"Times New Roman\",\"serif\"; color: black;'>{$NewString}</span></p>";
}
else{
$ReturnString .= "<p style='line-height:normal'><span style='font-size:12.0pt;font-family:\"Times New Roman\",\"serif\"; color: black;'><b>{$NewString}</b></span></p>";
}
}
return $ReturnString;
}
?>
Usage:
$Title = "{Which|What|Exactly which|Generally} {Diaper|Baby diaper|Nappy} {to|for you to|to actually|to positively} {Choose|Select|Pick|Decide on|Opt for}?";
$SpunArticle = myTruncate(Spin($Title),600);
echo $Article . $SpunArticle;