src/HTML.php
public static function convertToPlainText($html, $strip_urls = false, $html_format = false){

		$plain_text = $html;

		// Attempt to maintain some basic formatting

		$plain_text = str_replace('<li>', ' * ', $plain_text);
		$plain_text = str_replace(['</p>', '</h1>', '</h2>', '</h3>'],
			PHP_EOL . PHP_EOL, $plain_text);
		$plain_text = str_replace(['</ul>', '</ol>', '<br>', '</li>', '</h4>', '</h5>'],
			PHP_EOL, $plain_text);

		// Strip out all remaining HTML tags

		$plain_text = preg_replace('/<\/?.*>/iU', '', $plain_text);

		// Strip out everything that resembles a URL

		if($strip_urls){

			$pattern = '/(?:(?:https?\:\/\/(?:www\.)?)|(?:www\.))\S+\s?/i';
			$plain_text = preg_replace($pattern, '', $plain_text);
		}

		$plain_text = html_entity_decode($plain_text, ENT_QUOTES, DEFAULT_CHARSET);
		$plain_text = trim($plain_text);

		// Apply "HTML formatting" to the plain-text

		if($html_format){

			$plain_text = htmlentities($plain_text, ENT_QUOTES, DEFAULT_CHARSET);
			$plain_text = str_replace(PHP_EOL, '<br>', $plain_text);
			$plain_text = "<p>$plain_text</p>";
		}

		return $plain_text;
	}
public static function convertToPlainText($html, $strip_urls = false, $html_format = false){

		$plain_text = $html;

		// Attempt to maintain some basic formatting

		$plain_text = str_replace('<li>', ' * ', $plain_text);
		$plain_text = str_replace(['</p>', '</h1>', '</h2>', '</h3>'],
			PHP_EOL . PHP_EOL, $plain_text);
		$plain_text = str_replace(['</ul>', '</ol>', '<br>', '</li>', '</h4>', '</h5>'],
			PHP_EOL, $plain_text);

		// Strip out all remaining HTML tags

		$plain_text = preg_replace('/<\/?.*>/iU', '', $plain_text);

		// Strip out everything that resembles a URL

		if($strip_urls){

			$pattern = '/(?:(?:https?\:\/\/(?:www\.)?)|(?:www\.))\S+\s?/i';
			$plain_text = preg_replace($pattern, '', $plain_text);
		}

		$plain_text = html_entity_decode($plain_text, ENT_QUOTES, DEFAULT_CHARSET);
		$plain_text = trim($plain_text);

		// Apply "HTML formatting" to the plain-text

		if($html_format){

			$plain_text = htmlentities($plain_text, ENT_QUOTES, DEFAULT_CHARSET);
			$plain_text = str_replace(PHP_EOL, '<br>', $plain_text);
			$plain_text = "<p>$plain_text</p>";
		}

		return $plain_text;
	}
public static function convertToPlainText ( $ html , $ strip_urls = false , $ html_format = false ) { $ plain_text = $ html ; // Attempt to maintain some basic formatting $ plain_text = str_replace ( '<li>' , ' * ' , $ plain_text ) ; $ plain_text = str_replace ( [ '</p>' , '</h1>' , '</h2>' , '</h3>' ] , PHP_EOL . PHP_EOL , $ plain_text ) ; $ plain_text = str_replace ( [ '</ul>' , '</ol>' , '<br>' , '</li>' , '</h4>' , '</h5>' ] , PHP_EOL , $ plain_text ) ; // Strip out all remaining HTML tags $ plain_text = preg_replace ( '/<\/?.*>/iU' , '' , $ plain_text ) ; // Strip out everything that resembles a URL if ( $ strip_urls ) { $ pattern = '/(?:(?:https?\:\/\/(?:www\.)?)|(?:www\.))\S+\s?/i' ; $ plain_text = preg_replace ( $ pattern , '' , $ plain_text ) ; } $ plain_text = html_entity_decode ( $ plain_text , ENT_QUOTES , DEFAULT_CHARSET ) ; $ plain_text = trim ( $ plain_text ) ; // Apply "HTML formatting" to the plain-text if ( $ html_format ) { $ plain_text = htmlentities ( $ plain_text , ENT_QUOTES , DEFAULT_CHARSET ) ; $ plain_text = str_replace ( PHP_EOL , '<br>' , $ plain_text ) ; $ plain_text = "<p>$plain_text</p>" ; } return $ plain_text ; }
Convert HTML to plain-text.

<p>Convert (clean) HTML into plain-text. This method applies some very
basic formatting to maintain a bit of the previous appearance. This
method returns <em>pure</em> plain-text, including having all HTML
entities decoded.</p>

<p>This method <strong>only</strong> functions properly if it is fed
proper HTML (c.q. passed through {@link HTML::cleanHTML()}).</p>

<p>The optional argument {@link $strip_urls} is used to forcibly remove
everything that looks like a URL (c.q. starts with "http://" or "www.")
from the plain-text output.</p>

<p>The optional argument {@link $html_format} is used to "HTML format"
the returned plain-text. This entails all line-breaks are replaced with
an HTML "br" element, HTML ntities are re-encoded and the entire string
is wrapped in a single HTML paragraph element. This way the plain-text
can be displayed (as plain-text) in an HTML document.</p>

@param string $html
@param boolean $strip_urls
@param boolean $html_format
@return string
Convert HTML to plain - text .