Text Formatted Code
/**
* Turn a piece of HTML into continuous(!) plain text
*
* This function removes HTML tags, line breaks, etc. and returns one long
* line of text. This is useful for word counts (do an explode() on the result)
* and for text excerpts.
*
* @param string $text original text, including HTML and line breaks
* @return string continuous plain text
*
*/
function COM_getTextContent($text)
{
// replace <br> with spaces so that Text<br>Text becomes two words
$text = preg_replace('/\<br(\s*)?\/?\>/i', ' ', $text);
// add extra space between tags, e.g. <p>Text</p><p>Text</p>
$text = str_replace('><', '> <', $text);
// only now remove all HTML tags
$text = strip_tags($text);
// replace all tabs, newlines, and carrriage returns with spaces
$text = str_replace(array("\011", "\012", "\015"), ' ', $text);
// replace entities with plain spaces
$text = str_replace(array('', ' ', ' '), ' ', $text);
// collapse whitespace
$text = preg_replace('/\s\s+/', ' ', $text);
return trim($text);
}