"Contrast" PHP detects if the submitted paragraphs have duplicate lines, which is better?
Write two functions, comparing the text of the submitted paragraphs inside the repeating there is no, found some problems:
(1) In_array () Detection of Chinese some time there will be problems, obviously there is no hint exists, long text when the probability of higher
(2) Sometimes it is permissible to repeat three to four times in short paragraphs, but if you use Similar_text to make comparisons, you will not be allowed to submit the user once again. How to improve is better
(3) There is no better way, beg ~
function Hassimilartext ($string)
{
$LINEARR = explode ("\ n", $string);
$ARRSTR = $arrLen = Array ();
foreach ($lineArr as $k = $v)
{
$arrLen [] = strlen ($v);
$arrStr [] = $v;
}
foreach ($arrStr as $k 1 = $v 1)
{
foreach ($arrStr as $k 2 = $v 2)
{
if ($k 1 = = $k 2) continue;
if ($arrLen [$k 2] < | | ABS ($arrLen [$k 2]-$arrLen [$k 1]) > continue;
Similar_text ($v 1, $v 2, $pct);
if ($pct >) return true;
}
}
return false;
}
/* Repeat paragraph detection */
function Hasrepeatline ($string)
{
$string = Str_replace (Array ("\ T", "" "," @ "," # ",". ",", ",". ",", "),", $string);
$string = Str_replace ("\ r", "\ n", $string);
$LINEARR = explode ("\ n", $string);
$countShort = $countMiddle = $countLong = 0;
$arr = Array ();
foreach ($lineArr as $lineString)
{
$length = strlen ($lineString);
if ($length < 1) continue;
if (In_array ($lineString, $arr))
{
if ($length < 13)
{
$countShort + +;
if ($countShort > 4) return TRUE;//5 times
} elseif ($length >12 && $length < 51) {
$countMiddle + +;
if ($countMiddle > 3) return true; 4 plays
} elseif ($length >50 && $length < 101) {
$countLong + +;
if ($countLong > 2) return true; 3 plays