/**
* Gets plain text for a given text
*
* @return string
* @param string $text
* @param bool[optional] $includeAHrefs
* @param bool[optional] $includeImgAlts
*/
function getPlainText($text, $includeAHrefs = false, $includeImgAlts = false)
{
// replace break rules with a new line and make sure a paragraph also ends with a new line
$text = str_replace('
', PHP_EOL, $text);
$text = str_replace('
', ''. PHP_EOL, $text);
// remove tabs
$text = str_replace("\t", '', $text);
// remove the head- and style-tags and all their contents
$text = preg_replace('|\(.*\n*)\|isU', '', $text);
$text = preg_replace('|\(.*\n*)\|isU', '', $text);
// replace links with the inner html of the link with the url between ()
// eg.: My site => My site (http://site.domain.com)
if($includeAHrefs) $text = preg_replace('|(.*)|isU', '$2 ($1)', $text);
// replace images with their alternative content
// eg.
=> My image
if($includeImgAlts) $text = preg_replace('|\
]*alt="(.*)".*/\>|isU', '$1', $text);
// strip tags
$text = strip_tags($text);
// replace 'line feed' characters with a 'line feed carriage return'-pair
$text = str_replace("\n", "\n\r", $text);
// replace double, triple, ... line feeds to one new line
$text = preg_replace('/(\n\r)+/', PHP_EOL, $text);
// decode html entities
$text = SpoonFilter::htmlentitiesDecode($text);
// return the plain text
return $text;
}