Clean textarea field content

@param   string  $str  Field content
@return  string Cleaned string
352850
public static function cleanTextarea($str)
  {
    $str = str_replace('&nbsp;', ' ', $str);
    $str = preg_replace("/[\r\n]{2,}/", "\n\n", $str);
    $str = preg_replace("/<br([^>]*)>/", "\n", $str);
    
    if ( !preg_match("/<(p|table|figure|div|h[1-6])>.+<\/$1>/", $str) ){
      $str = '<p>'.$str.'</p>';
    }
    $str = preg_replace("/\n\n/", "</p> <p>", $str);
    $str = trim($str);
    $str = preg_replace("/<p>\s*<\/p>/", "", $str);
    $str = preg_replace("/\n/", "<br />", $str);
    $str = trim($str);
    
    return $str;
  }
439666
protected function strip_all($str) {
		$str = $this->strip_whitespace($str);
		$str = $this->strip_images($str);
		$str = $this->strip_scripts($str);
		return $str;
	}
741815
function clean_string($str)
	{
		if ($this->_is_ascii($str) === FALSE)
		{
			$str = @iconv('UTF-8', 'UTF-8//IGNORE', $str);
		}

		return $str;
	}
217166
public static function toSlug($str)
  {
    $str = str_replace('-', ' ', $str);
    $str = str_replace("’", "'", $str);
    $str = self::removeAccents($str);
    $str = preg_replace("/\s+/", " ", $str);
    $str = trim(mb_strtolower($str));
    $str = preg_replace('/(\s|[^A-Za-z0-9\-])+/', '-', $str);
    $str = trim($str, '-');
    return $str;
  }
292707
function encode($str) {
		return @htmlspecialchars($str,$this->hive['BITMASK'],
			$this->hive['ENCODING'])?:$this->scrub($str);
	}
1255152
public static function sanitizeFilename($str)
    {
        $replace_chars = array(
            'Š'=>'S', 'š'=>'s', 'Ð'=>'Dj','Ž'=>'Z', 'ž'=>'z', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A',
            'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E', 'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I',
            'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U', 'Ú'=>'U',
            'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss','à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a',
            'å'=>'a', 'æ'=>'a', 'ç'=>'c', 'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i',
            'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o', 'ö'=>'o', 'ø'=>'o', 'ù'=>'u',
            'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y', 'ƒ'=>'f'
        );
        $str = strtr($str, $replace_chars);
        $str = preg_replace(array('/[\&]/', '/[\@]/', '/[\#]/'), array('-and-', '-at-', '-number-'), $str);
        $str = preg_replace('/[^(\x20-\x7F)]*/','', $str); // removes any special chars we missed
        $str = str_replace(' ', '-', $str); // convert space to hyphen
        $str = str_replace('\'', '', $str); // removes apostrophes
        $str = preg_replace('/[^\w\-\.]+/', '', $str); // remove non-word chars (leaving hyphens and periods)
        $str = preg_replace('/[\-]+/', '-', $str); // converts groups of hyphens into one

        return strtolower($str);
    }
773332
public static function decode(String $str) : String
    {
        return str_replace(array_values(self::$phpTagChars), array_keys(self::$phpTagChars), $str);
    }
755740
public static function stripControlChars( $str ) {

		if( is_array($str) ) {
			foreach( $str as &$item ) {
				$item = static::stripControlChars($item);
			}
			return $str;
		}

		do {
			// 00-08, 11, 12, 14-31, 127
			$str = preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/Su', '', $str, -1, $count);
		}
		while ($count);

		return $str;

	}
44545
function (str) {
            return _(str).chain()
                .unescapeHTML()
                .stripTags()
                .clean()
                .value()
                .replace( matchJunk, '' )
                .toLowerCase();
        }
816933
public static function cleanFileName($str)
    {
        preg_match('~\.\w{1,4}$~', $str, $ext);

        $str = preg_replace('~\.\w{1,4}$~', '', $str);

        return str_replace(Array(' ', '.', '-'), "_", $str).$ext[0];
    }
275135
public static function removeAccents($str, $charset = 'utf-8') {
        $str = htmlentities($str, ENT_NOQUOTES, $charset);
        $str = preg_replace('#\&([A-za-z])(?:acute|cedil|circ|grave|ring|tilde|uml|uro)\;#', '\1', $str);
        $str = preg_replace('#\&([A-za-z]{2})(?:lig)\;#', '\1', $str);
        $str = preg_replace('#\&[^;]+\;#', '', $str);

        return $str;
    }
1182403
public static function strrev($str)
    {
        $result = '';
        $strLen = static::length($str);

        if (!$strLen) {
            return $result;
        }

        for ($i = $strLen - 1; $i >= 0; $i--) {
            $result .= static::substr($str, $i, 1);
        }

        return $result;
    }
1148109
public function escape($str = '')
    {
        $config = \HTMLPurifier_Config::createDefault();
        $config->set('Cache.SerializerPath', $this->cachePath);
        if (!empty($this->config) && is_array($this->config) && count($this->config) > 0) {
            foreach ($this->config as $key => $value) {
                $config->set($key, $value);
            }
        }
        $purifier = new \HTMLPurifier($config);
        $clean    = $purifier->purify($str);

        return $clean;
    }
43540
public static function  trim($str,$charlist='')
    {
        if($charlist == '') return trim($str);

        return self::ltrim(self::rtrim($str));
    }
155816
protected function _fixBlanks($str)
    {
        $lines = explode(PHP_EOL, $str);
        $clean = array();
        foreach ($lines as $line) {
            if (trim($line) != "") {
                $clean[] = $line;
            }
        }

        return implode(PHP_EOL, $clean);
    }
332267
private function unescapeLatinCharacters($str)
    {
        if ($this->latinCharacters) {
            $str = vsprintf($str, $this->latinCharacters);
            $this->latinCharacters = array();
        }

        return $str;
    }
535643
private function _clean_input_data($str) {
		if (is_array($str)) {
			$new_array = array();
			foreach ($str as $key => $val) {
				$new_array[$this->_clean_input_keys($key)] = $this->_clean_input_data($val);
			}
			return $new_array;
		}
		
		/*
		 * We strip slashes if magic quotes is on to keep things consistent
		 * NOTE: In PHP 5.4 get_magic_quotes_gpc() will always return 0 and it
		 * will probably not exist in future versions at all.
		 */
		if (get_magic_quotes_gpc()) {
			$str = stripslashes($str);
		}
		
		// Remove control characters
		$str = Security::remove_invisible_characters($str);
		
		// Should we filter the input data?
		if ($this->_enable_xss === TRUE) {
			$str = Security::xss_clean($str);
		}
		
		// Standardize newlines if needed
		if ($this->_standardize_newlines == TRUE) {
			if (strpos($str, "\r") !== FALSE) {
				$str = str_replace(array("\r\n", "\r", "\r\n\n"), PHP_EOL, $str);
			}
		}
		
		return $str;
	}