1. Enter the following into the Baidu search box: 中困要要要要乱说乱动器在要困要要要在要无误仙客来要是要要粉黛将军肚要呆要要因要两手空空在 要手榴弹要要在顺在手榴弹要在右要要要要. The final search results are shown in the image below:

2. Write the function qstrlen, the code is as follows:
/**
* dstrlen // kcuc
* @param string $str
* @return string $count One Chinese character represents two lengths
*/
function qstrlen($str) {
$count = 0;
$len = 0;
for ($i = 0; $i < strlen($str); $i++) {
$value = ord($str[$i]);
if($value > 127) {
$count++;
if ($value >= 192 && $value <= 223) {
$i++;
} elseif ($value >= 224 && $value <= 239) {
$i = $i + 2;
} elseif ($value >= 240 && $value <= 247) {
$i = $i + 3;
}
}
$count++;
if ($count > 76 && $len == 0) {
$len = $i;
$subject = mb_strcut($str, 0, $len, ‘utf-8’);
}
if ($count > 82) {
return [$subject, str_replace($subject, ”, mb_strcut($str, 0, $i, ‘utf-8’))];
break;
}
}
if ($count > 76 && $count <= 82) {
return [$subject, str_replace($subject, ”, mb_strcut($str, 0, null, ‘utf-8’))];
}
return $count;
}
3. The code screenshot is as follows (one Chinese character represents 2 lengths, so 38 needs to be multiplied by 2, and “要两手” has a length of 3 Chinese characters, so its length in the function is 6):

4. Call the string truncation function, its code and screenshot are as follows:

5. Evaluate and display the prompt message in the web template:

6. If the final search keyword exceeds 38 Chinese characters in length, the display effect is as follows:

7. Compare the search effect for mixed Chinese, English, and numeric keywords with Baidu. Search for: 中困要要要要乱说乱动器8d88847yudghdjuhfhryhw27在要困要要要ssssssssss在要无误仙客shjdjssdddd来要是要要粉黛将军肚要呆要要因. The results are as follows:


