"Contrast" PHP detects if the submitted paragraphs have duplicate lines, which is better? Solutions

Source: Internet
Author: User
"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
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.