$tmpstr = "";
$strlen = $start + $len;
for($i = 0; $i < $strlen; $i++) {
if(ord(substr($gbk, $i, 1)) > 0xa0) {
$tmpstr .= substr($gbk, $i, 2);
$i++;
} else
$tmpstr .= substr($gbk, $i, 1);
}
return $tmpstr;
};
2、修改views_trim_text函數:
function views_trim_text($alter, $value) {
$gbk=mb_convert_encoding($value, "GBK", "UTF-8");//增長的
//dsm(strlen($gbk));
//dsm($value);
if (
strlen($gbk) > $alter['max_length']) { //將drupal_
strlen
修改成 strlen
//$value = drupal_substr($value, 0, $alter['max_length']);
$u8 = gbsubstr($gbk, 0, $alter['max_length']);//可處理漢字,代替上一行
$value=mb_convert_encoding($u8, "UTF-8", "GBK");
//增長的
//dsm($value);
// TODO: replace this with cleanstring of ctools
if (!empty($alter['word_boundary'])) {
$regex = "(.*)\b.+";
if (function_exists('mb_ereg')) {
mb_regex_encoding('UTF-8');
$found = mb_ereg($regex, $value, $matches);
}
else {
$found = preg_match("/$regex/us", $value, $matches);
}
if ($found) {
$value = $matches[1];
}
}
// Remove scraps of HTML entities from the end of a strings
$value = rtrim(preg_replace('/(?:<(?!.+>)|&(?!.+;)).*$/us', '', $value));
if (!empty($alter['ellipsis'])) {
$value .= '...';
}
}
if (!empty($alter['html'])) {
$value = _filter_htmlcorrector($value);
}
return $value;
}
3、增長連接的title提示
通常截斷標題後須要增長連接的title提示,以表達未截斷前的完整含義。
修改views_handler_field.inc
文件:
在function render_as_link函數中返回前增長一行: if (isset($tokens['[title]'])) $options['attributes']['title'] = $tokens['[title]'];//added by zc 搞定。