[Comparison] which of the following is better if PHP checks whether the submitted paragraphs have repeated rows? I wrote two functions, compared to the submitted text section, and found some problems: (1) in_array () I found that there are some problems in Chinese, but I was prompted that there was no such problem, the probability of long text is higher (2) Sometimes the short paragraph repeats 3 ~ 4 [comparison] which of the following is better if PHP checks whether the submitted paragraphs have repeated rows?
The two functions are compared to the submitted text paragraphs, and some problems are found:
(1) the in_array () method is used to detect Chinese characters, but the system prompts that the text does not exist. the probability of long text is higher.
(2) Sometimes the short paragraph repeats 3 ~ It is allowed for four times, but if similar_text is used for comparison, the user will be rejected if there is a duplicate. How to improve
(3) Is there any better method ~
Function hasSimilarText ($ string)
{
$ LineArr = explode ("\ n", $ string );
$ ArrStr = $ arrLen = array ();
Foreach ($ lineArr as $ k => $ v)
{
$ ArrLen [] = strlen ($ v );
$ ArrStr [] = $ v;
}
Foreach ($ arrStr as $ k1 => $ v1)
{
Foreach ($ arrStr as $ k2 => $ v2)
{
If ($ k1 = $ k2) continue;
If ($ arrLen [$ k2] <30 | abs ($ arrLen [$ k2]-$ arrLen [$ k1])> 100) continue;
Similar_text ($ v1, $ v2, $ pct );
If ($ pct> 90) return true;
}
}
Return false;
}
/* Duplicate 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 times
} Elseif ($ length> 50 & $ length <101 ){
$ CountLong ++;
If ($ countLong> 2) return true; // 3 times