1. Enter in the Baidu search box: in the middle of the poor If you want a grenade, you have to be in the grenade, you need it on the right, and the final search results are as follows:

2. Write the function qstrlen, the code is as follows:
/**
* dstrlen // kcuc
* @param string $str
* @return string $count a Chinese character means 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 screenshot of the code is as follows (one Chinese character represents 2 lengths, so 38 needs to be multiplied by 2, and “two hands” is the length of 3 Chinese characters, so the length in the function is 6):

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

5. Determine and display the prompt information in the web page template:

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

7. Comparing the search effect of Chinese and English plus numbers with Baidu hw27 is going to have to be sleepy, and it needs to be ssssssssss.


Leave a Reply