sanitize a string (detect html tags, add slashes and remove sql orders)

@param string $data String to sanitize
@return string Sanitized string
333828
static function sanitize($data)
	{
		// remove whitespaces (not a must though)
		//$data = filter_var(trim($data), FILTER_SANITIZE_STRING, !FILTER_FLAG_STRIP_LOW);
		$data = trim(strip_tags($data));
		
		// apply stripslashes if magic_quotes_gpc is enabled
		if(get_magic_quotes_gpc())
			$data = stripslashes($data);
			
		// SQL commands are forbidden
		$banlist = array
			(
			"/alter /i", "/insert /i", "/select /i", "/update /i", "/delete /i", "/distinct /i", "/having /i", "/truncate /i", "/replace /i",
			"/handler /i", "/like /i", "/procedure /i", "/limit /i", "/order by /i", "/group by /i" , "/drop /i", "/database /i"
			);
			
		$data = preg_replace($banlist, '', $data);
		
		return $data;
	}
959248
protected function cleanData($data)
    {
        $originalFields = $this->getFields();
        $uniqueId       = $this->getUniqueId();
        $fields         = array_merge(
            $originalFields,
            array($uniqueId));

        // clean data from data item
        foreach ($data as $fieldName => $value) {
            if (array_search($fieldName, $fields) === false) {
                unset($data[ $fieldName ]);
            }
        }

        if (isset($data[ $uniqueId ]) && empty($data[ $uniqueId ])) {
            unset($data[ $uniqueId ]);
        }

        return $data;
    }
627632
protected function clean($string)
    {
        if ($this->format == 'xml') {
            return $string;
        }

        $string = html_entity_decode($string, ENT_QUOTES, 'UTF-8');
        $string = htmlentities($string, ENT_QUOTES, 'UTF-8');

        if (function_exists('mb_convert_encoding')) {
            $string = mb_convert_encoding($string, 'UTF-8');
        } else {
            $string = utf8_decode($string);
        }

        return $string;
    }
109506
public function xssClean($data)
    {
        // If its empty there is no point cleaning it :\
        if (empty($data)) {
            return $data;
        }

        // Recursive loop for arrays
        if (is_array($data)) {
            foreach ($data as $key => $value) {
                $data[$key] = $this->xssClean($data);
            }

            return $data;
        }

        // Fix &entity\n;
        $data = $this->fixEntity($data);

        // Remove any attribute starting with "on" or xmlns
        $data = preg_replace('#(<[^>]+?[\x00-\x20"\'])(?:on|xmlns)[^>]*+>#iu', '$1>', $data);

        // Remove javascript: and vbscript: protocols
        $data = $this->removeJavaScriptProtocols($data);

        $data = $this->removeVbScriptProtocols($data);

        $data = preg_replace(
            '#([a-z]*)[\x00-\x20]*=([\'"]*)[\x00-\x20]*-moz-binding[\x00-\x20]*:#u',
            '$1=$2nomozbinding...',
            $data
        );

        // Only works in IE: <span style="width: expression(alert('Ping!'));"></span>
        $data = $this->fixIe($data);

        // Remove namespaces elements (we do not need them)
        $data = $this->removeNameSpaceElements($data);

        $data = preg_replace($this->sqlReplace, '', $data);

        do {
            // Remove really unwanted tags
            $old_data = $data;
            $data = preg_replace(
                '#</*(?:applet|b(?:ase|gsound|link)|embed|frame(?:set)?|i(?:frame|layer)|l
                (?:ayer|ink)|meta|object|s(?:cript|tyle)|title|xml)[^>]*+>#i',
                '',
                $data
            );
        } while ($old_data !== $data);

        return htmlentities($data);
    }
47401
public function cleanKeys($data)
    {
        $pregMatches = (bool) preg_match(self::PREG_PROPERTIES, '?');
        $chars = '';
        $chars = $pregMatches ? '\pL' : 'a-zA-Z';


        if (!preg_match('#^['.$chars.'0-9:_.-]++$#uD', $data)) {
            throw new \Exception('Illegal key characters in global data');
        }

        return $data;
    }
433012
protected static function getUrlSafeData($data)
    {
        $remainder = strlen($data) % 4;

        if ($remainder) {
            $data .= str_repeat('=', 4 - $remainder);
        }

        return strtr($data, '-_', '+/');
    }
536754
private function sanitize($rules, $blockData)
    {
        /**
         * Sanitize every key in data block
         */
        foreach ($blockData as $key => $value) {
            /**
             * PHP Array has integer keys
             */
            if (is_integer($key)) {
                $rule = $rules[BlockHandler::DEFAULT_ARRAY_KEY];
            } else {
                $rule = $rules[$key];
            }

            $rule = $this->expandToolSettings($rule);
            $elementType = $rule['type'];

            /**
             * Sanitize string with Purifier
             */
            if ($elementType == 'string') {
                $allowedTags = isset($rule['allowedTags']) ? $rule['allowedTags'] : '';
                if ($allowedTags !== '*') {
                    $blockData[$key] = $this->getPurifier($allowedTags)->purify($value);
                }
            }

            /**
             * Sanitize nested elements
             */
            if ($elementType == 'array') {
                $blockData[$key] = $this->sanitize($rule['data'], $value);
            }
        }

        return $blockData;
    }
45750
static public function sanitizeInjectively($string) {
        $sanitized = '';
        foreach (str_split($string) as $char) {
            $sanitized .= isset(self::$ALLOWED_CHARACTERS[$char]) ? $char : '='.base64_encode($char);
        }
        return $sanitized;
    }
662233
protected function cleanSaveData(
        &$data
    ) {
        if (empty($data)) {
            return;
        }

        if (is_array($data)) {
            ksort($data);

            foreach ($data as &$arrayData) {
                $this->cleanSaveData($arrayData);
            }

            return;
        }

        if (is_string($data)) {
            $data = trim(
                str_replace(
                    [
                        "\n",
                        "\t",
                        "\r"
                    ],
                    "",
                    $data
                )
            );
        }

        return;
    }
1266371
protected static function normalize($data)
    {
        foreach ($data as $id => $value) {
            $data[$id] = strtoupper(NoDiacritic::filter($value));
        }
        return $data;
    }
1048745
protected static function _parseTex(string $data) {
        preg_match('{\\$\\$([\\S\\s]*?)\\$\\$}', $data, $matches);
        if (isset($matches[0])) {
            $str = str_replace(["\r", "\n"], '', $matches[1]);
            return $str;
        }
        return false;
    }
828609
final public function sanitize($data)
    {
        if ($this->_walk && (is_array($data) || is_object($data))) {
            $arr = (array)$data;

            foreach ($arr as $key => $value) {
                if (is_array($data)) {
                    $data[$key] = $this->sanitize($value);
                }

                if (is_object($data)) {
                    $data->$key = $this->sanitize($value);
                }
            }
        } else {
            $context = $this->_chain->getContext();
            $context->data = $data;

            $data = $this->_chain->run('sanitize', $context);
        }

        return $data;
    }
638027
public function sanitizeGlossaryTerm( $data ) {
		if ( isset( $data['post_type'], $data['post_content'] ) && $data['post_type'] === 'glossary' ) {
			$data['post_content'] = wp_kses(
				$data['post_content'],
				[
					'a' => [
						'href' => [],
						'target' => [],
					],
					'br' => [],
					'em' => [],
					'p' => [],
					'strong' => [],
				]
			);
		}
		return $data;
	}
783232
private function doXssClean($data)
    {
        if (is_array($data) && count($data)) {
            foreach ($data as $k => &$v) {
                $v = $this->doXssClean($data[$k]);
            }

            return $data;
        }

        if (trim($data) === '') {
            return $data;
        }

        // xss_clean function from Kohana framework 2.3.1
        $data = str_replace(['&amp;', '&lt;', '&gt;'], ['&amp;amp;', '&amp;lt;', '&amp;gt;'], $data);
        $data = preg_replace('/(&#*\w+)[\x00-\x20]+;/u', '$1;', $data);
        $data = preg_replace('/(&#x*[0-9A-F]+);*/iu', '$1;', $data);
        /** @noinspection CallableParameterUseCaseInTypeContextInspection */
        $data = html_entity_decode($data, ENT_COMPAT, 'UTF-8');

        // Remove any attribute starting with "on" or xmlns
        $data = preg_replace('#(<[^>]+?[\x00-\x20"\'])(?:on|xmlns)[^>]*+>#iu', '$1>', $data);

        // Remove javascript: and vbscript: protocols
        $data = preg_replace('#([a-z]*)[\x00-\x20]*=[\x00-\x20]*([`\'"]*)[\x00-\x20]*j[\x00-\x20]*a[\x00-\x20]*v[\x00-\x20]*a[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iu',
            '$1=$2nojavascript...', $data);
        $data = preg_replace('#([a-z]*)[\x00-\x20]*=([\'"]*)[\x00-\x20]*v[\x00-\x20]*b[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iu',
            '$1=$2novbscript...', $data);
        $data = preg_replace('#([a-z]*)[\x00-\x20]*=([\'"]*)[\x00-\x20]*-moz-binding[\x00-\x20]*:#u',
            '$1=$2nomozbinding...', $data);

        // Only works in IE: <span style="width: expression(alert('Ping!'));"></span>
        $data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?expression[\x00-\x20]*\([^>]*+>#i',
            '$1>', $data);
        $data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?behaviour[\x00-\x20]*\([^>]*+>#i',
            '$1>', $data);
        $data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:*[^>]*+>#iu',
            '$1>', $data);

        // Remove namespaced elements (we do not need them)
        $data = preg_replace('#</*\w+:\w[^>]*+>#i', '', $data);

        do {
            // Remove really unwanted tags
            $old_data = $data;
            $data = preg_replace('#</*(?:applet|b(?:ase|gsound|link)|embed|frame(?:set)?|i(?:frame|layer)|l(?:ayer|ink)|meta|object|s(?:cript|tyle)|title|xml)[^>]*+>#i',
                '', $data);
        } while ($old_data !== $data);

        return $data;
    }
744975
public function convertToString($data) {
		if (!is_string($data)) {
			$data = @json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
			// Removing null byte and double slashes from object properties
			$data = str_replace(['\\u0000', '\\\\'], ["", "\\"], $data);
		}

		return $data;
	}
1094263
private static function sanitize(array &$data)
    {
        $blackList = array_combine(self::config()->loggingBlacklist, self::config()->loggingBlacklist);
        array_walk_recursive($data, function (&$value, $key) use ($blackList) {
            if (isset($blackList[$key])) {
                $value = '(sanitized)';
            }
        });
    }
985683
protected function _sanitize($value)
    {
        $string = htmlentities(utf8_decode($value));
        $string = preg_replace(
            array('/&szlig;/','/&(..)lig;/', '/&([aouAOU])uml;/','/&(.)[^;]*;/'),
            array('ss',"$1","$1".'e',"$1"),
            $string
        );

        return $string;
    }