Protects value from XSS injection by replacing some characters by XML / HTML entities
@param string $input The unprotected value
@return string A safe string
768711
public static function unXSS($input)
    {
        $return = '';
        if (version_compare(phpversion(), '5.4', '<')) {
            $return = htmlspecialchars($input);
        } else {
            $return = htmlentities($input, ENT_QUOTES | ENT_DISALLOWED | static::$outputLanguage);
        }

        return $return;
    }
799497
protected function _outputXML($input) {
		$attributes = '';
		$output = '';
		
		// get attributes
		foreach ($input as $key => $value) {
			$attribute = [];

			if ($key[0] == $this->attribute_tag) {
				$newkey = substr($key, 1);
				foreach ($value as $pkey => $pvalue) {
					$attribute[] = $pkey.'="'.htmlspecialchars($pvalue).'"';
				}
				$attributes[$newkey] = implode(' ', $attribute);
				unset($input[$key]);
			}
		}

		// run through all keys
		foreach ($input as $key => $value) {
			// set attribs
			if (isset($attributes[$key])) $attr = ' '.$attributes[$key]; else $attr = '';

			// process numeric indices
			if (is_numeric($key)) $key = $this->numeric_prefix.$key;

			if (is_array($value) && count($value) > 0) {
				$body = $this -> _outputXML($value);
			} else {
				// process value
				if (is_array($value)) $value = '';
				elseif ($value === true) $value = 'true';
				elseif ($value === false) $value = 'false';
				elseif ($value === null) $value = 'null';
				else {
					$value = trim(stripslashes($value));

					if (strpos($value, '<') !== false OR strpos($value, '>') !== false OR strpos($value, '&') !== false) {
						$value = '<![CDATA['.$value.']]>';
					}
				}

				$body = $value;
			}

			// process equal named tags
			$key = explode($this->strip_tag, $key);
			$key = $key[0];

			// Start-Tag setzen
			if (!isset($output)) $output = '';
			$output .= '<'.$key.$attr.'>';
			$output .= $body;
			// End-Tag setzen
			$output .= '</'.$key.'>';
		}
		return $output;
	}
1036393
public static function toStudlyCase($input) {
		$input = trim($input, '-_');
		return ucfirst(preg_replace_callback('/([A-Z-_][a-z]+)/', function($matches) {
			return ucfirst(str_replace(['-','_'], '',$matches[0]));
		}, $input));
	}
1109229
public function verifySalt($input)
    {
        $appearsValid = (1 === preg_match('/^_[\.\/0-9A-Za-z]{8}$/', $input));
        if ($appearsValid) {
            $costFactor = $this->_decodeInt24(substr($input, 1, 4));
            if ($costFactor < 1 || $costFactor > (1 << 24) - 1) {
                $appearsValid = false;
            }
        }

        return $appearsValid;
    }
130163
public function validateRegexp(string $input): bool
    {
        $output = true;
        set_error_handler(function (int $severity, string $message) use (&$output) {
            if (strpos($message, 'preg_replace(): ') === 0) {
                $output = false;
            } else {
                return false;
            }
        }, E_WARNING | E_DEPRECATED);
        preg_replace($input, '', '');
        restore_error_handler();
        return $output
            ? preg_match("/^\\/[^\\p{C}\\p{Z}\\p{M}A-Zァ-ヶ\u{10000}-\u{10FFFD}]+\\/$/u", $input) === 1
            : false;
    }
1069957
public static function encryptPassword($input)
    {
        $rndStr=strtolower(self::getRandomString(32));
        $mixedStr=$rndStr.$input;
        return $rndStr.md5($mixedStr);
    }
51435
static String escapeText(final String input)
    {
        return escapeBytes(ByteBuffer.wrap(input.getBytes(ISO_8859_1))).toString();
    }
713830
public function escape($input)
    {
        $input = strtolower($input);
        $input = preg_replace('/[^a-z0-9_. -]+/', '', $input);
        $input = trim($input);
        $input = str_replace(' ', '_', $input);
        $input = preg_replace('/_{2,}/', '_', $input);

        return $input;
    }
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;
    }
309449
public static function bin2ascii($input)
    {
        $hextab = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        $result = '';

        for ($x = 0; $x < strlen($input); $x++) {
            $result .= $hextab[ord($input[$x]) % 62];
        }

        return $result;
    }
673504
public function fixName($input)
    {
        if (!preg_match("/^([a-z]|[A-Z])+.*$/", $input)) {
            $input = "q_" . $input;
        }
        $input = str_replace(array(" ", "-", ":", ";", "!", "/", "\\", "'"), array("_", "_hyph_", "_dd_", "_dc_", "_excl_", "_fs_", "_bs_", '_qu_'), $input);
        return $input;
    }
258709
public function escapeBytea(string $input): string
    {
        if ($this->resource->getType() != Resource::TYPE_PGSQL_LINK) {
            throw new AgentException('escapeBytea() available for only Pgsql!');
        }

        return pg_escape_bytea($this->resource->getObject(), $input);
    }
920119
public function encode($input)
    {
        $parts = explode('.', $input);

        foreach ($parts as &$part) {
            $part = $this->_encodePart($part);
        }

        return implode('.', $parts);
    }
247587
public static function cleanSpaces($input)
    {
        $nonbreaking_space = chr(0xC2) . chr(0xA0);
        $search_spaces = ['<p>&nbsp;</p>', '&nbsp;', $nonbreaking_space, ' '];
        $replace_spaces = ['', ' ', ' ', ' '];
        $out = str_replace($search_spaces, $replace_spaces, $input);
        $out = trim(preg_replace('/\s{2,}/', ' ', $out));
        return $out;
    }
1175943
public static function validate($input)
    {
        if (is_string($input)) {
            $doc = new DOMDocument();
            $doc->preserveWhiteSpace = false;

            if (!@$doc->loadXML($input)) {
                throw InvalidXmlException::lastError();
            }

            $input = $doc;
        } elseif (!($input instanceof DOMDocument)) {
            throw InvalidArgumentException::create(
                'The $input argument must be an instance of DOMDocument, %s given.',
                gettype($input)
            );
        }

        if (!@$input->schemaValidate(self::SCHEMA)) {
            throw InvalidXmlException::lastError();
        }
    }
175281
private static String escapeXml(String input) {
        return input == null ? "" : input.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;");
    }
473411
public static function encode($input, $serialized = false)
    {
        // use Base64 encoding to workaround issues with invalid
        // or null characters in serialized string (#1489142)
        if ($serialized) {
            return base64_encode(serialize($input));
        }

        if (is_object($input)) {
            foreach (get_object_vars($input) as $idx => $value) {
                $input->$idx = self::encode($value);
            }
            return $input;
        }
        else if (is_array($input)) {
            foreach ($input as $idx => $value) {
                $input[$idx] = self::encode($value);
            }

            return $input;
        }

        return utf8_encode($input);
    }