JavaScript截断字符串,类似于substr(),只不过这个函数不会截断单词,在发生截断后,会添加一个省略号
if (!function_exists('subsent')) { function subsent($string, $start = 0, $length = 0, $cap = '...') { if ($length <= 0 || strlen($string) < $length) { return $string; } $string = substr($string, $start, strpos($string, ' ', $length)) . ' ' . $cap; return $string; } }