/** * trims text to a space then adds ellipses if desired * @param string $input text to trim * @param int $length in characters to trim to * @param bool $ellipses if ellipses (...) are to be added * @param bool $strip_html if html tags are to be stripped * @return string */ function trim_text($input, $length, $ellipses = true, $strip_html = true) { //strip tags, if desired if ($strip_html) { $input = strip_tags($input); } //no need to trim, already shorter than trim length if (strlen($input) <= $length) { return $input; } //find last space within length $last_space = strrpos(substr($input, 0, $length), ' '); $trimmed_text = substr($input, 0, $last_space); //add ellipses (...) if ($ellipses) { $trimmed_text .= '...'; } return $trimmed_text; } function sluggify($url) { # Prep string with some basic normalization $url = strtolower($url); $url = strip_tags($url); $url = stripslashes($url); $url = html_entity_decode($url); # Remove quotes (can't, etc.) $url = str_replace('\'', '', $url); # Replace non-alpha numeric with hyphens $match = '/[^a-z0-9]+/'; $replace = '-'; $url = preg_replace($match, $replace, $url); $url = trim($url, '-'); return $url; } ?>
Looks like you got lost!