Removes HTML tags from the given string while maintaining whitespace.

@param string $string

@return string
194490
public function removeTags($string)
    {
        // Remove HTML Tags:
        
        $string = preg_replace('/<[^>]*>/', ' ', $string);
        
        // Remove Control Characters:
        
        $string = str_replace("\r", '',  $string);  // replace with empty space
        $string = str_replace("\n", ' ', $string); // replace with single space
        $string = str_replace("\t", ' ', $string); // replace with single space
        
        // Remove Multiple Spaces:
        
        $string = trim(preg_replace('/ {2,}/', ' ', $string));
        
        // Answer String:
        
        return $string;
    }
607499
public static function strip_all_tags($string, $remove_breaks = false)
    {
        $string = preg_replace('@<(script|style)[^>]*?>.*?</\\1>@si', '', $string);
        $string = strip_tags($string);

        if ($remove_breaks) {
            $string = preg_replace('/[\r\n\t ]+/', ' ', $string);
        }

        return trim($string);
    }
935695
public function replaceTokens($string)
    {
        foreach ($this->getTokenNames($string) as $token) {
            $string = str_replace("{{$token}}", $this->getTokenValue($token), $string);
        }
        
        return $string;
    }
1195641
public static function cleanExtension(?string $string): ?string
    {
        // no extension in string is founded
        if (!self::contains('.', $string)) {
            return $string;
        }

        $splited = explode('.', $string);
        array_pop($splited);
        return implode('.', $splited);
    }
519839
protected function sensible($string)
    {
        $string = preg_replace('`([A-Z])`', '-\1', $string);
        $string = str_replace(array('-', '_'), ' ', $string);

        return ucfirst(trim(strtolower($string)));
    }
65015
public function cleanUrl($string)
    {
        // First replace ampersands with the word 'and'
        $string = str_replace('&', 'and', $string);

        // Remove slashes
        $string = str_replace('/', '-', $string);

        // Strip out any single quotes
        $string = str_replace("'", '', $string);

        // Remove unwelcome characters, and replace with dashes
        $string = preg_replace('/[^a-zA-Z0-9]+/', '-', $string);

        // Lower case
        $string = mb_strtolower($string);

        // Finally remove and trailing dashes
        $string = trim($string, '-');

        return $string;
    }
252230
static
	public String trim(String string){
		int length = string.length();

		int trimmedLength = length;

		while(trimmedLength > 0){
			char c = string.charAt(trimmedLength - 1);

			if(!Character.isWhitespace(c)){
				break;
			}

			trimmedLength--;
		}

		if(trimmedLength < length){
			string = string.substring(0, trimmedLength);
		}

		return string;
	}
1181545
private function clean(string $string, bool $space_remove = true)
    {
        $string = trim($string);
        if ($space_remove) {
            $string = str_replace(' ', '-', $string);
        }
        return preg_replace('/[^A-Za-z0-9\-][_]/', '', $string);
    }
712941
public static function stringUrlUnicodeSlug($string)
	{
		// Replace double byte whitespaces by single byte (East Asian languages)
		$str = preg_replace('/\xE3\x80\x80/', ' ', $string);

		// Remove any '-' from the string as they will be used as concatenator.
		// Would be great to let the spaces in but only Firefox is friendly with this

		$str = str_replace('-', ' ', $str);

		// Replace forbidden characters by whitespaces
		$str = preg_replace('#[:\#\*"@+=;!><&\.%()\]\/\'\\\\|\[]#', "\x20", $str);

		// Delete all '?'
		$str = str_replace('?', '', $str);

		// Trim white spaces at beginning and end of alias and make lowercase
		$str = trim(StringHelper::strtolower($str));

		// Remove any duplicate whitespace and replace whitespaces by hyphens
		$str = preg_replace('#\x20+#', '-', $str);

		return $str;
	}
535968
private function trimLast($string)
        {
            $length = strlen($string) - 1;

            if (Arrays::in($string{$length}, array('t', 'x'))) {
                $string = substr($string, 0, $length);
            }
        }
1289491
public static function cleanText(string $text)
    {
        $text = preg_replace('/<script[^>]*>.*?</script>/si', '', $text);
        $text = preg_replace('/<a\s+.*?href="([^"]+)"[^>]*>([^<]+)<\/a>/is', '\2 (\1)', $text);
        $text = preg_replace('/<!--.+?-->/', '', $text);
        $text = preg_replace('/{.+?}/', '', $text);
        $text = preg_replace('/&nbsp;/', ' ', $text);
        $text = preg_replace('/&amp;/', ' ', $text);
        $text = preg_replace('/&quot;/', ' ', $text);
        $text = strip_tags($text);
        $text = htmlspecialchars($text);

        return $text;
    }
112285
public function process($string)
    {
        preg_match_all($this->tagFilter, $string, $matches);

        if (!$matches) {
            return $string;
        }

        foreach ($matches[0] as $i => $m) {
            if (array_key_exists($matches[1][$i], $this->styles)) {
                $string = $this->replaceColors(
                    $string,
                    $matches[1][$i],
                    $matches[2][$i],
                    $this->styles[$matches[1][$i]]
                );
            } elseif (strpos($matches[1][$i], '=')) {
                // Custom format
                $string = $this->replaceColors(
                    $string,
                    $matches[1][$i],
                    $matches[2][$i],
                    ColorStyle::fromString($matches[1][$i])
                );
            }
        }

        return $string;
    }
1022624
private function filterSpecialCharacters($string)
    {
        $string = str_replace('<', ' <',
            $string); // This is need, otherwise this: <h1>something</h1><h2>something</h2> will result in somethingsomething
        $string = strip_tags($string);
        $string = trim($string);
        $string = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $string); // Remove special alphanumeric characters
        $string = str_replace(array('+', '=', '!', ',', '.', ';', ':', '?'), ' ',
            $string); // Replace sentence breaking charaters with spaces
        $string = preg_replace("/[\r\n]+/", " ", $string); // Replace multiple newlines with a single space.
        $string = preg_replace("/[\t]+/", " ", $string); // Replace multiple tabs with a single space.
        $string = preg_replace("/[^a-zA-Z0-9 ]/", '',
            $string); // Filter out everything that is not alphanumeric or a space
        $string = preg_replace('!\s+!', ' ', $string); // Replace multiple spaces with a single space
        return $string;
    }
1250413
public static function sanitize_string($string)
    {
        $string = self::remove_accents($string);
        $string = strtolower($string);
        $string = preg_replace('/[^a-zA-Z 0-9]+/', '', $string);
        $string = self::strip_space($string);

        return $string;
    }
299783
public static function toSingleWhitespace($string, $trim = true)
    {
        $string = preg_replace("/\r|\n|\t/", " ", $string);
        $string = preg_replace("/ {2,}/", " ", $string);

        if ($trim) {
            $string = self::trim($string);
        }

        return $string;
    }
496796
private function stringToUsernameChunk($string)
    {
        $string = trim((string) $string);
        $string = preg_replace('/[^a-z0-9]+/', '_', strtolower($string));
        $string = preg_replace('/__+/', '_', $string);
        $string = trim($string, '_');

        return $string;
    }
740421
public static function stringURLUnicodeSlug($string)
    {
        // Replace double byte whitespaces by single byte (East Asian languages)
        $str = preg_replace('/\xE3\x80\x80/', ' ', $string);

        // Remove any '-' from the string as they will be used as concatenator.
        // Would be great to let the spaces in but only Firefox is friendly with this

        $str = str_replace('-', ' ', $str);

        // Replace forbidden characters by whitespaces
        $str = preg_replace('#[:\#\*"@+=;!><&\.%()\]\/\'\\\\|\[]#', "\x20", $str);

        // Delete all '?'
        $str = str_replace('?', '', $str);

        // Trim white spaces at beginning and end of alias and make lowercase
        $str = trim(UnicodeHelper::strtolower($str));

        // Remove any duplicate whitespace and replace whitespaces by hyphens
        $str = preg_replace('#\x20+#', '-', $str);

        return $str;
    }