Remove Invisible Characters

This prevents sandwiching null characters
between ascii characters, like Java\0script.

@access	private
@param	string
@return	string
766538
function _remove_invisible_characters($str)
	{
		static $non_displayables;

		if ( ! isset($non_displayables))
		{
			// every control character except newline (dec 10), carriage return (dec 13), and horizontal tab (dec 09),
			$non_displayables = array(
										'/%0[0-8bcef]/',			// url encoded 00-08, 11, 12, 14, 15
										'/%1[0-9a-f]/',				// url encoded 16-31
										'/[\x00-\x08]/',			// 00-08
										'/\x0b/', '/\x0c/',			// 11, 12
										'/[\x0e-\x1f]/'				// 14-31
									);
		}

		do
		{
			$cleaned = $str;
			$str = preg_replace($non_displayables, '', $str);
		}
		while ($cleaned != $str);

		return $str;
	}
1213095
public static function strip($str)
    {
        $ascii = '';
        for($i=0; $i<strlen($str); $i++){
            if(ord($str{$i}) <128){
                $ascii .= $str{$i};
            }
        }
        return $ascii;
    }
1176987
public static function removeAccents($text){
    static $diac;
    return strtr(
      utf8_decode($text),
      $diac ? $diac : $diac = utf8_decode('àáâãäçèéêëìíîïñòóôõöùúûüýÿÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝ'),
      'aaaaaceeeeiiiinooooouuuuyyAAAAACEEEEIIIINOOOOOUUUUY');
  }
697297
public static function clean($string)
	{
		if (empty($string))
		{
			return $string;
		}

		if (get_magic_quotes_gpc())
		{
			$string = stripslashes($string);
		}

		// strip out any KL_PHP, script, style, HTML comments
		$string = preg_replace('/{kl_php}(.*?){\/kl_php}/is', '', $string);
		$regex =
			'/(<link[^>]+rel="[^"]*stylesheet"[^>]*>|' .
			'<script[^>]*>.*?<\/script>|' .
			'<style[^>]*>.*?<\/style>|' .
			'<\?php.*?\?>|' .
			'<!--.*?-->)/is';
		$string = preg_replace($regex, '', $string);

		$string = str_replace(
			array('&amp;',     '&lt;',     '&gt;'),
			array('&amp;amp;', '&amp;lt;', '&amp;gt;'),
			$string
		);
		// Fix &entitiy\n;

		$string = preg_replace('#(&\#*\w+)[\x00-\x20]+;#u', "$1;", $string);
		$string = preg_replace('#(&\#x*)([0-9A-F]+);*#iu', "$1$2;", $string);
		//$string = html_entity_decode($string, ENT_COMPAT, "UTF-8");

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

		// Remove javascript: and vbscript: protocol
		$string = 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]*:#iUu', '$1=$2nojavascript...', $string);
		$string = 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]*:#iUu', '$1=$2novbscript...', $string);

		// <span style="width: expression(alert('Ping!'));"></span>
		// only works in ie...
		$string = preg_replace('#(<[^>]+)style[\x00-\x20]*=[\x00-\x20]*([\`\'\"]*).*expression[\x00-\x20]*\([^>]*>#iU', "$1>", $string);
		$string = preg_replace('#(<[^>]+)style[\x00-\x20]*=[\x00-\x20]*([\`\'\"]*).*behaviour[\x00-\x20]*\([^>]*>#iU', "$1>", $string);
		$string = 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]*:*[^>]*>#iUu', "$1>", $string);

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

		// Remove really unwanted tags
		$string = self::stripTags($string,
			'applet', 'meta', 'xml', 'blink', 'link', 'style',
			'script', 'embed', 'object', 'iframe', 'frame', 'frameset',
			'ilayer', 'layer', 'bgsound', 'title', 'base'
		);

		return $string;
	}
429796
function (string) {
			var ascii = "";

			for (var i = 0; i < string.length; i++) {
				ascii += string.charCodeAt(i) + ",";
			}

			// remove last ","
			ascii = ascii.substring(0, ascii.length - 1);

			return ascii;
		}
702813
public static function clearString( string $string ) {
		$string = trim( $string );
		$string = stripslashes( $string );
		$string = htmlspecialchars( $string );

		return $string;
	}
578832
function removeSpecialCharacter($name) {
        $lowerName = strtolower($name);
        $what = array( 'ä','ã','à','á','â','ê','ë','è','é','ï','ì','í','ö','õ','ò','ó','ô','ü','ù','ú','û','À','Á','É','Í','Ó','Ú','ñ','Ñ','ç','Ç',' ','-','(',')',',',';',':','|','!','"','#','$','%','&','/','=','?','~','^','>','<','ª','º', "'" );
        $by   = array( 'a','a','a','a','a','e','e','e','e','i','i','i','o','o','o','o','o','u','u','u','u','A','A','E','I','O','U','n','n','c','C','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-', '-');

        return str_replace($what, $by, $lowerName);
    }
1073068
private static function UnescapeReplacementString( $str )
	{
		$result = "";
		$charArr = str_split ( $str );

		for ( $k = 0; $k < count( $charArr ); $k++ )
		{
			if ( $charArr[ $k ] == '\\' )
			{
				if ( $k == count( $charArr ) - 1 )
					throw XPath2Exception::withErrorCodeAndParam( "FORX0004", Resources::FORX0004, $str );

					switch ( $charArr[ $k + 1 ] )
					{
						case 'n':
							$result .= "\n";
							break;

						case 'r':
							$result .="\r";
							break;

						case 't':
							$result .= "\t";
							break;

						case 'a':
							$result .= "\a";
							break;

						case '\\':
							$result .= "\\";
							break;

						default:
							throw XPath2Exception::withErrorCodeAndParam( "FORX0004", Resources::FORX0004, $str );
					}
					$k++;
			}
			else
				$result .= $charArr[ $k ];
		}
		return $result;
	}
1135977
protected function removeBadCharLast( $string ) {
		if ( $string != '' ) {
			$char = ord( $string[strlen( $string ) - 1] );
			$m = array();
			if ( $char >= 0xc0 ) {
				# We got the first byte only of a multibyte char; remove it.
				$string = substr( $string, 0, -1 );
			} elseif ( $char >= 0x80 &&
				  preg_match( '/^(.*)(?:[\xe0-\xef][\x80-\xbf]|' .
							  '[\xf0-\xf7][\x80-\xbf]{1,2})$/', $string, $m ) )
			{
				# We chopped in the middle of a character; remove it
				$string = $m[1];
			}
		}
		return $string;
	}
1160391
function (ascii) {
			var asciiArray = ascii.split(",");
			var parsedString = "";

			jQuery.each(asciiArray, function (index, asciiChar) {
				parsedString += String.fromCharCode(asciiChar);
			});

			return parsedString;

		}
825494
private function removeTerminationNull(string $value)
    {
        $i = strpos((string)$value, "\0");
        if ($i === false) {
            return $value;
        }

        $result = substr((string)$value, 0, $i);

        return $result;
    }
90821
def removeNullPadding(str, blocksize=AES_blocksize):
    ''
    pad_len = 0    
    for char in str[::-1]: # str[::-1] reverses string
        if char == '\0':
            pad_len += 1
        else:
            break
    str = str[:-pad_len]
    return str
568000
public static function cleanForOrder(string $str): string
  {
    $str = self::removeAccents($str);
    $str = preg_replace("/^[^a-z0-9 ]/i", "", $str);
    $str = trim($str);
    return $str;
  }
435151
function clean(source) {
    if (!source) return BLANK;
    if (source.charCodeAt(0) === BOM_CODE) source = source.slice(1);
    source = source.replace(CR_REGEXP, BLANK).replace(TRAILING_WHITESPACE_REGEXP, BLANK);
    return source;
}
583160
function phpEscape(s) {
  var result = '"';
  for (let cp of UnicodeUtils.getCodePoints(s)) {
    let special = specialEscape[cp];
    if (special !== undefined) {
      result += special;
    } else if (cp >= 0x20 && cp <= 0x7e) {
      result += String.fromCodePoint(cp);
    } else if (cp <= 0xFFFF) {
      result += '\\u{' + zeroPaddedHex(cp, 4) + '}';
    } else {
      result += '\\u{' + zeroPaddedHex(cp, 6) + '}';
    }
  }
  result += '"';
  return result;
}
325785
public function clean($value)
  {
    // Return null for empty strings.
    if ($value==='' || $value===null || $value===false)
    {
      return null;
    }

    // Replace all ambiguous characters.
    $tmp = $value;
    foreach ($this->ambiguities as $unambiguity => $ambiguities)
    {
      foreach ($ambiguities as $ambiguity)
      {
        // Note: str_replace works fine with multi byte characters like UTF-8.
        $tmp = str_replace($ambiguity, $unambiguity, $tmp);
      }
    }

    // Restore EOL for DOS users.
    if (PHP_EOL!="\n") $tmp = str_replace("\n", PHP_EOL, $tmp);

    // Return null for empty strings.
    if ($tmp==='') $tmp = null;

    return $tmp;
  }
830265
private function htmlEncode($data)
    {
        if (empty($data)) {
            return null;
        }

        $safeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890._-";

        $result = "";
        for ($i = 0; $i < strlen($data); $i++) {
            if (strstr($safeChars, $data[$i])) {
                $result .= $data[$i];
            } else if ("7F" >= $var = bin2hex(substr($data, $i, 1))) {
                $result .= "&#x" . $var . ";";
            } else {
                $result .= $data[$i];
            }
        }

        return $result;
    }