function substrs($content,$length,$add='Y'){ if (strlen($content)>$length) { if ($ GLOBALS['db_charset']!='utf-8') { $retstr = ''; for ($i=0;$i$retstr .= ord($content[$i]) > $content[$i].$content[++$i] : $content[$i] return $retstr.($add=='Y) ' ? ' ..' : ''); } utf8_trim(substr($content,0,$length)).($add=='Y' ? ' ..' : ''); $content を返す ; 関数 utf8_trim($str) { $hex = ''; $len = strlen($str)-1; for ($i=$len;$i>=0;$i -=1 ) { $ch = ord($str[$i]); $hex .= " $ch"; if (($ch & 128)==0 || ($ch & 192)= =192) { return substr($str,0,$i); } } return $str.$hex; }
function Cutstr($string, $length, $dot = ' ...' ) { グローバル $charset; if(strlen($string) <= $length) { return $string; } $string = str_replace(array('&', '"', '<', '> ')、array('&', '"', '<', '>'), $string); $strcut = ''; if(strto lower($charset) == 'utf -8' ) { $n = $tn = $noc = 0; while($n < strlen($string)) { $t = ord($string[$n]); == 9 || $t == 10 || (32 <= $t && $t <= 126)) { $n++ = 1; t && $ t <= 223) { $tn = 2; $n += 2; $noc += 2; } elseif(224 <= $t && $t <= 239) { = 3; $n += 2; } elseif(240 <= $t && $t <= 247) { $n += 4; 2; } elseif(248 <= $t && $t <= 251) { $tn = 5; $noc += 2; $t = = 253) { $tn = 6; $noc += 2; } if($noc >= $length) { break; } } if($noc > $length) { $n -= $tn; } $strcut = substr($string, 0, $n) } else { for($i = 0; $i $strcut .= ord($string[$i]) > 127 ? $string[$i] $i] ; } } $strcut = str_replace(array('&', '"', '<', '>'), array('&', '"', '<', '> '), $strcut); $strcut.$dot
http://www.bkjia.com/PHPjc/444721.html
www.bkjia.com
本当
http://www.bkjia.com/PHPjc/444721.html |
技術記事