This article is introduced in PHP comes with a truncated string function, can only handle English, the number can not intercept the Chinese mixed, oh, there is a need for friends to reference, the latter is more useful, the first is mainly for beginners to learn to use.
| The code is as follows |
Copy Code |
/*
------------------------------------------------------
Parameters:
$str _cut The string to be truncated
$length maximum length allowed for string display
Program function: Intercept full-width and half-width (kanji and English) mixed strings to avoid garbled characters
------------------------------------------------------
*/
function Substr_cut ($str _cut, $length)
{
if (strlen ($str _cut) > $length)
{
for ($i =0; $i < $length; $i + +)
if (Ord ($str _cut[$i]) > $i + +;
$str _cut = substr ($str _cut,0, $i). "...";
}
return $STR _cut;
}
?>
|
http://www.bkjia.com/PHPjc/445327.html www.bkjia.com true http://www.bkjia.com/PHPjc/445327.html techarticle This article is introduced in PHP comes with a truncated string function, can only handle English, the number can not intercept the Chinese mixed, oh, there is a need for friends to reference, the latter is more useful, ...