Removes any non-alphanumeric characters.

@param   string  $string   String to sanitize
@param   array   $allowed  An array of additional characters that are not to be removed.
@return  string  Sanitized string
356892
public static function paranoid($string, $allowed = array())
	{
		$allow = null;
		if (!empty($allowed))
		{
			foreach ($allowed as $value)
			{
				$allow .= "\\$value";
			}
		}

		if (!is_array($string))
		{
			return preg_replace("/[^{$allow}a-zA-Z0-9]/", '', $string);
		}

		$cleaned = array();
		foreach ($string as $key => $clean)
		{
			$cleaned[$key] = preg_replace("/[^{$allow}a-zA-Z0-9]/", '', $clean);
		}

		return $cleaned;
	}
76272
protected static function safeStrlen($string)
    {
        // Optimization -- only search once:
        static $exists = null;
        if ($exists === null) $exists = \function_exists('mb_strlen');
        if ($exists) return \mb_strlen($string, '8bit');
        return \strlen($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);
    }
95291
protected static function decode(string $component, string $allowed): string
    {
        $allowed = sprintf('/[%s]/', $allowed);
        $encoded = sprintf('/%s/', static::PCT_ENCODED_SET);

        return preg_replace_callback($encoded, function ($matches) use ($allowed) {
            $char = rawurldecode($matches[0]);

            if (preg_match($allowed, $char)) {
                return $char;
            }

            return strtoupper($matches[0]);
        }, $component);
    }
741815
function clean_string($str)
	{
		if ($this->_is_ascii($str) === FALSE)
		{
			$str = @iconv('UTF-8', 'UTF-8//IGNORE', $str);
		}

		return $str;
	}
962538
private function stripAccents($string){
		$string = utf8_decode($string);
		$string = strtr($string,
						utf8_decode('Ã Ã¡Ã¢Ã£Ã¤Ã§Ã¨Ã©ÃªÃ«Ã¬Ã­Ã®Ã¯Ã±Ã²Ã³Ã´ÃµÃ¶Ã¹ÃºÃ»Ã¼Ã½Ã¿Ã€Ã�Ã‚ÃƒÃ„Ã‡ÃˆÃ‰ÃŠÃ‹ÃŒÃ�ÃŽÃ�Ã‘Ã’Ã“Ã”Ã•Ã–Ã™ÃšÃ›ÃœÃ�'),
						'aaaaaceeeeiiiinooooouuuuyyAAAAACEEEEIIIINOOOOOUUUUY');
		return utf8_encode($string);
	}
649525
public static function removeUnsafeChars($str) {
		static $blacklist = '/[!\"?():\']/';
		static $whitelist = '/[^a-zA-Z0-9-_.]/';
		$validStr = preg_replace(array($blacklist, $whitelist), array('', '-'), $str);
		return $validStr;
	}
589175
public function convertNewlines($string) {
        $string = str_replace("\r\n", "\n", $string);
        $string = str_replace("\r", "\n", $string);

        return $this->cleanNewlines($string);
    }
641092
protected function normalizeString($string)
    {
        if (false === strpos($string, '_')) {
            return $string;
        }

        return preg_replace_callback('/_([a-zA-Z0-9])/', function ($matches) {
            return strtoupper($matches[1]);
        }, $string);
    }
441107
public static function sanitizeLength($input, $maxLen)
    {
        if(isset($input[$maxLen]))     // take string as array of chars
            return substr($input,0,$maxLen);
        else
            return $input;
    }
461863
public static function ascii($str, $allow_non_ascii = false)
	{
		// Translate unicode characters to their simpler counterparts
		\Config::load('ascii', true);
		$foreign_characters = \Config::get('ascii');

		$str = preg_replace(array_keys($foreign_characters), array_values($foreign_characters), $str);

		if ( ! $allow_non_ascii)
		{
			return preg_replace('/[^\x09\x0A\x0D\x20-\x7E]/', '', $str);
		}

		return $str;
	}
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;
    }
519839
protected function sensible($string)
    {
        $string = preg_replace('`([A-Z])`', '-\1', $string);
        $string = str_replace(array('-', '_'), ' ', $string);

        return ucfirst(trim(strtolower($string)));
    }
74048
public static function removeLeft($string, $search, $encoding = null)
    {
        if ($string === '') {
            return '';
        }

        if ($search === '') {
            return $string;
        }

        $encoding = $encoding === null ? mb_internal_encoding() : $encoding;

        if (!static::startsWith($string, $search, true, $encoding)) {
            return $string;
        }

        return Mbstring::substr($string, Mbstring::strlen($search), null, $encoding);
    }
532214
public static function sanearString($string, $exclude_guion = true) {
        $string = trim($string);
        $string = str_replace(
            array('á', 'à', 'ä', 'â', 'ª', 'Á', 'À', 'Â', 'Ä'),
            array('a', 'a', 'a', 'a', 'a', 'A', 'A', 'A', 'A'),
            $string
        );
        $string = str_replace(
            array('é', 'è', 'ë', 'ê', 'É', 'È', 'Ê', 'Ë'),
            array('e', 'e', 'e', 'e', 'E', 'E', 'E', 'E'),
            $string
        );
        $string = str_replace(
            array('í', 'ì', 'ï', 'î', 'Í', 'Ì', 'Ï', 'Î'),
            array('i', 'i', 'i', 'i', 'I', 'I', 'I', 'I'),
            $string
        );
        $string = str_replace(
            array('ó', 'ò', 'ö', 'ô', 'Ó', 'Ò', 'Ö', 'Ô'),
            array('o', 'o', 'o', 'o', 'O', 'O', 'O', 'O'),
            $string
        );
        $string = str_replace(
            array('ú', 'ù', 'ü', 'û', 'Ú', 'Ù', 'Û', 'Ü'),
            array('u', 'u', 'u', 'u', 'U', 'U', 'U', 'U'),
            $string
        );
        $string = str_replace(
            array('ñ', 'Ñ', 'ç', 'Ç'),
            array('n', 'N', 'c', 'C',),
            $string
        );
        //Esta parte se encarga de eliminar cualquier caracter extraño
        $string = str_replace(
            array("\\", "¨", "º", "~",
                "#", "@", "|", "!", "\"",
                "·", "$", "%", "&", "/",
                "(", ")", "?", "'", "¡",
                "¿", "[", "^", "`", "]",
                "+", "}", "{", "¨", "´",
                ">", "< ", ";", ",", ":",
                "."),
            '',
            $string
        );

        if($exclude_guion) {
            $string = str_replace(array("-","_"), '', $string);
        }

        return $string;
    }
573728
public static function urlifyUtf8($string, array $allowedCharacters = array(), $delimiter = ' ')
    {
        $urlValue = $string;
        $urlValue = str_replace('/', '', $urlValue);
        $urlValue = self::replaceNewlines($urlValue, $delimiter);
        $urlValue = preg_replace(array('~[?%]~iu', '~[^\x{0000}-\x{FFFF}a-zA-Z0-9.,\~!*()\'_' . implode('', $allowedCharacters) . '-]~iu', '~' . $delimiter . '+~'), $delimiter, $urlValue);
        $urlValue = trim($urlValue);

        return $urlValue;
    }
773472
public static function safe(string $string) : string
  {
    $split = str_split($string);

    foreach($split as $k => $char) {
      if (str_contains('~!@#$%^&*()_-=+<>/\?;:{}[]|,.', $char)) {
        unset($split[$k]);
      }
    }

    return implode('', $split);
  }