bug fix in truncate function
This commit is contained in:
parent
335f159c78
commit
78968aaf4d
|
@ -256,20 +256,12 @@ class Text {
|
|||
$string);
|
||||
}
|
||||
|
||||
// Truncates the string under the limit specified by the limit parameter.
|
||||
// Truncates the string under the limit specified by the limit parameter
|
||||
public static function truncate($string, $limit, $end='...')
|
||||
{
|
||||
// Check if over $limit
|
||||
if (mb_strlen($string) > $limit) {
|
||||
|
||||
// Check if string is only one word
|
||||
if(preg_match('/\s/', $string)) {
|
||||
|
||||
// Append the string specified by the end parameter to the end of the string as it is over the limit.
|
||||
$truncate = trim(mb_substr($string, 0, mb_strpos($string, ' ', $limit, CHARSET), CHARSET));
|
||||
} else {
|
||||
$truncate = trim(mb_substr($string, 0, $limit, CHARSET));
|
||||
}
|
||||
$truncate = $truncate.$end;
|
||||
} else {
|
||||
$truncate = $string;
|
||||
|
|
|
@ -603,10 +603,12 @@ class Pages extends dbJSON {
|
|||
|
||||
|
||||
// Returns string without HTML tags and truncated
|
||||
private function generateSlug($text, $truncateLength=60) {
|
||||
private function generateSlug($text, $truncateLength=60)
|
||||
{
|
||||
$tmpslug = Text::removeHTMLTags($text);
|
||||
$tmpslug = Text::removeLineBreaks($tmpslug);
|
||||
return Text::truncate($tmpslug, $truncateLength, '');
|
||||
$tmpslug = Text::truncate($tmpslug, $truncateLength, '');
|
||||
return $tmpslug;
|
||||
}
|
||||
|
||||
// Returns TRUE if there are new pages published, FALSE otherwise
|
||||
|
|
Loading…
Reference in New Issue