< ? php /** * Using this function, we can break ( substr ) a string without losing html tags, * * @param $text * String which is to be shortened. * * @param $length * The length of the string . * * @param $ending * The string that is to be appended after shortening. Defaults to … * * @param boolean $exact * If false, $text will not be cut mid-word * * @param boolean $considerHtml * If true, HTML tags would be handled correctly * * * @return * string Trimmed string.. */ Function _html_substr ($text, $length = 100, $ending = '...', $exact = false, $considerHtml = true) { if ($considerHtml) { // If the plain text is shorter than the maximum length, return the whole text if (strlen ( preg_replace ( '/<.*?>/', '', $text)) <= $length) { return $text; } ...