static function processWhitespaceNewlines($text) {

		// remove excess spaces around tabs
		$text = preg_replace("/ *\t */im", "\t", $text);

		// remove leading whitespace
		$text = ltrim($text);

		// remove leading spaces on each line
		$text = preg_replace("/\n[ \t]*/im", "\n", $text);

		// convert non-breaking spaces to regular spaces to prevent output issues,
		// do it here so they do NOT get removed with other leading spaces, as they
		// are sometimes used for indentation
		$text = static::renderText($text);

		// remove trailing whitespace
		$text = rtrim($text);

		// remove trailing spaces on each line
		$text = preg_replace("/[ \t]*\n/im", "\n", $text);

		// unarmor pre blocks
		$text = static::fixNewLines($text);

		// remove unnecessary empty lines
		$text = preg_replace("/\n\n\n*/im", "\n\n", $text);

		return $text;
	}
static function processWhitespaceNewlines($text) {

		// remove excess spaces around tabs
		$text = preg_replace("/ *\t */im", "\t", $text);

		// remove leading whitespace
		$text = ltrim($text);

		// remove leading spaces on each line
		$text = preg_replace("/\n[ \t]*/im", "\n", $text);

		// convert non-breaking spaces to regular spaces to prevent output issues,
		// do it here so they do NOT get removed with other leading spaces, as they
		// are sometimes used for indentation
		$text = static::renderText($text);

		// remove trailing whitespace
		$text = rtrim($text);

		// remove trailing spaces on each line
		$text = preg_replace("/[ \t]*\n/im", "\n", $text);

		// unarmor pre blocks
		$text = static::fixNewLines($text);

		// remove unnecessary empty lines
		$text = preg_replace("/\n\n\n*/im", "\n\n", $text);

		return $text;
	}
static function processWhitespaceNewlines ( $ text ) { // remove excess spaces around tabs $ text = preg_replace ( "/ *\t */im" , "\t" , $ text ) ; // remove leading whitespace $ text = ltrim ( $ text ) ; // remove leading spaces on each line $ text = preg_replace ( "/\n[ \t]*/im" , "\n" , $ text ) ; // convert non-breaking spaces to regular spaces to prevent output issues, // do it here so they do NOT get removed with other leading spaces, as they // are sometimes used for indentation $ text = static :: renderText ( $ text ) ; // remove trailing whitespace $ text = rtrim ( $ text ) ; // remove trailing spaces on each line $ text = preg_replace ( "/[ \t]*\n/im" , "\n" , $ text ) ; // unarmor pre blocks $ text = static :: fixNewLines ( $ text ) ; // remove unnecessary empty lines $ text = preg_replace ( "/\n\n\n*/im" , "\n\n" , $ text ) ; return $ text ; }
Remove leading or trailing spaces and excess empty lines from provided multiline text

@param string $text multiline text any number of leading or trailing spaces or excess lines
@return string the fixed text
Remove leading or trailing spaces and excess empty lines from provided multiline text