/** * Cleans up text for special output. * * Namely for use inside 'title' attributes. Strips HTML, removes double-quotes (since * that's what this demo uses for attributes), reduces all linebreaks and multiple * spaces into a single space, and can shorten a string to a number of characters. * * @access public * @param string $s The string of text to clean up. * @param integer $length The number of characters to return in the description. * @return string The cleaned up string. */ function cleanup($s, $length = 0) { // Convert all HTML entities to their character counterparts. $s = html_entity_decode($s, ENT_QUOTES, 'UTF-8'); // Strip out HTML tags. $s = strip_tags($s); // Get rid of double quotes so they don't interfere with the title tag. $s = str_replace('"', '', $s); // Strip out superfluous whitespace and line breaks. $s = preg_replace('/(\\s+)/', ' ', $s); // Shorten the string to the number of characters requested (multibyte safe), and strip wrapping whitespace. if ($length > 0 && strlen($s) > $length) { $s = trim(newsblocks::substr($s, 0, $length, 'UTF-8')) . '…'; } // Return the value. return $s; }