/** * @dataProvider execute_provider */ public function test_exeute($string = null, $limit = null, $truncated_marker = null, $is_html = null, $is_special_chars = null, $expected = null) { $truncater = new Util_StrTruncater(array('truncated_marker' => $truncated_marker, 'is_html' => $is_html, 'is_special_chars' => $is_special_chars)); $test = $truncater->execute($string, $limit); $this->assertEquals($expected, $test); }
public static function truncate($body, $limit, $trimmarker = '...', $is_html = true, $is_special_chars = false) { $before_count = mb_strlen($body); $truncater = new Util_StrTruncater(array('truncated_marker' => $trimmarker, 'is_html' => $is_html, 'is_special_chars' => $is_special_chars)); $body = $truncater->execute($body, $limit); $is_truncated = mb_strlen($body) < $before_count; return array($body, $is_truncated); }
/** * Truncates a string to the given length. It will optionally preserve * HTML tags if $is_html is set to true. * * @param string $string the string to truncate * @param int $limit the number of characters to truncate too * @param string $continuation the string to use to denote it was truncated * @param bool $is_html whether the string has HTML * @return string the truncated string */ public static function truncate($string, $limit, $continuation = '...', $is_html = false) { $truncater = new Util_StrTruncater(array('truncated_marker' => $continuation, 'is_html' => $is_html, 'is_special_chars' => $is_html)); return $truncater->execute($string, $limit); }