Get PHP character encoding

@param $html_charset

@return string
172911
private static function getPhpEncoding( $html_charset )
    {
        $php_encoding = null;

        switch( strtolower($html_charset) ){
            case 'sjis':
            case 'sjis-win':
            case 'shift_jis':
            case 'shift-jis':
            case 'ms_kanji':
            case 'csshiftjis':
            case 'x-sjis':
                $php_encoding = 'sjis-win';
                break;
            case 'euc-jp':
            case 'cseucpkdfmtjapanese':
                $php_encoding = 'EUC-JP';
                break;
            case 'jis':
                $php_encoding = 'jis';
                break;
            case 'iso-2022-jp':
            case 'csiso2022jp':
                $php_encoding = 'ISO-2022-JP';
                break;
            case 'iso-2022-jp-2':
            case 'csiso2022jp2':
                $php_encoding = 'ISO-2022-JP-2';
                break;
            case 'utf-8':
            case 'csutf8':
                $php_encoding = 'UTF-8';
                break;
            case 'utf-16':
            case 'csutf16':
                $php_encoding = 'UTF-16';
                break;
            default:
                if ( strpos($html_charset,'sjis') ){
                    $php_encoding = 'SJIS';
                }
                break;
        }

        return $php_encoding;
    }
1071992
static function &charsetList()
    {
        $charsets =& $GLOBALS["eZMBCharsetList"];
        if ( !is_array( $charsets ) )
        {
            $charsetList = array( "ucs-4", "ucs-4be", "ucs-4le", "ucs-2", "ucs-2be", "ucs-2le", "utf-32", "utf-32be", "utf-32le", "utf-16",
                                  "utf-16be", "utf-16le", "utf-8", "utf-7", "ascii", "euc-jp", "sjis", "eucjp-win", "sjis-win", "iso-2022-jp", "jis",
                                  "iso-8859-1", "iso-8859-2", "iso-8859-3", "iso-8859-4", "iso-8859-5", "iso-8859-6", "iso-8859-7", "iso-8859-8",
                                  "iso-8859-9", "iso-8859-10", "iso-8859-13", "iso-8859-14", "iso-8859-15", "byte2be", "byte2le", "byte4be",
                                  "byte4le", "base64", "7bit", "8bit", "utf7-imap" );
            $charsets = array();
            foreach ( $charsetList as $charset )
            {
                $charsets[$charset] = $charset;
            }
        }
        return $charsets;
    }
614910
protected function _getContentTypeCharset()
    {
        $charset = strtoupper($this->charset);
        if (array_key_exists($charset, $this->_contentTypeCharset)) {
            return strtoupper($this->_contentTypeCharset[$charset]);
        }

        return strtoupper($this->charset);
    }
1258110
protected final Charset getCharset() {
    return mediaType == null || mediaType.getCharsetParameter() == null
        ? Charsets.ISO_8859_1
        : mediaType.getCharsetParameter();
  }
773092
public function checkEncoding($str, $charset)
    {
        $mb = $this->getMbCharset($charset);
        if ($mb !== false) {
            return mb_check_encoding($str, $mb);
        }
        $ic = $this->getIconvAlias($charset);
        return (@iconv($ic, $ic, $str) !== false);
    }
497641
public String[] getHtml2CharMapping () {
    	m_Html2Char[0] = " ";	//&#32
    	m_Html2Char[1] = "!";
    	m_Html2Char[2] = "\"";
    	m_Html2Char[3] = "#";	
    	m_Html2Char[4] = "$";	//36
    	m_Html2Char[5] = "%";
    	m_Html2Char[6] = "&";
    	m_Html2Char[7] = "'";
    	m_Html2Char[8] = "(";
    	m_Html2Char[9] = ")";	//41
    	m_Html2Char[10] = "*";
    	m_Html2Char[11] = "+";
    	m_Html2Char[12] = ",";
    	m_Html2Char[13] = "-";
    	m_Html2Char[14] = ".";	//46
    	m_Html2Char[15] = "/";	
    	m_Html2Char[16] = "0";
    	m_Html2Char[17] = "1";
    	m_Html2Char[18] = "2";
    	m_Html2Char[19] = "3";	//51
    	m_Html2Char[20] = "4";
    	m_Html2Char[21] = "5";
    	m_Html2Char[22] = "6";
    	m_Html2Char[23] = "7";
    	m_Html2Char[24] = "8";	//56
    	m_Html2Char[25] = "9";
    	m_Html2Char[26] = ":";
    	m_Html2Char[27] = ";";
    	m_Html2Char[28] = "<";
    	m_Html2Char[29] = "=";	//61
    	m_Html2Char[30] = ">";
    	m_Html2Char[31] = "?";
    	m_Html2Char[32] = "@";
    	m_Html2Char[33] = "A";
    	m_Html2Char[34] = "B";	//66
    	m_Html2Char[35] = "C";
    	m_Html2Char[36] = "D";
    	m_Html2Char[37] = "E";
    	m_Html2Char[38] = "F";
    	m_Html2Char[39] = "G";	//71
    	m_Html2Char[40] = "H";
    	m_Html2Char[41] = "I";
    	m_Html2Char[42] = "J";
    	m_Html2Char[43] = "K";
    	m_Html2Char[44] = "L";	//76
    	m_Html2Char[45] = "M";
    	m_Html2Char[46] = "N";
    	m_Html2Char[47] = "O";
    	m_Html2Char[48] = "P";
    	m_Html2Char[49] = "Q";	//81
    	m_Html2Char[50] = "R";
    	m_Html2Char[51] = "S";
    	m_Html2Char[52] = "T";
    	m_Html2Char[53] = "U";
    	m_Html2Char[54] = "V";	//86
    	m_Html2Char[55] = "W";
    	m_Html2Char[56] = "X";
    	m_Html2Char[57] = "Y";
    	m_Html2Char[58] = "Z";
    	m_Html2Char[59] = "[";	//91
    	m_Html2Char[60] = "\\";
    	m_Html2Char[61] = "]";
    	m_Html2Char[62] = "^";
    	m_Html2Char[63] = "_";
    	m_Html2Char[64] = "`";	//96
    	m_Html2Char[65] = "a";		
    	m_Html2Char[66] = "b";
    	m_Html2Char[67] = "c";
    	m_Html2Char[68] = "d";
    	m_Html2Char[69] = "e";	//101
    	m_Html2Char[70] = "f";
    	m_Html2Char[71] = "g";
    	m_Html2Char[72] = "h";
    	m_Html2Char[73] = "i";
    	m_Html2Char[74] = "j";	//106
    	m_Html2Char[75] = "k";
    	m_Html2Char[76] = "l";
    	m_Html2Char[77] = "m";
    	m_Html2Char[78] = "n";
    	m_Html2Char[79] = "o";	//111
    	m_Html2Char[80] = "p";
    	m_Html2Char[81] = "q";
    	m_Html2Char[82] = "r";
    	m_Html2Char[83] = "s";
    	m_Html2Char[84] = "t";	//116
    	m_Html2Char[85] = "u";
    	m_Html2Char[86] = "v";
    	m_Html2Char[87] = "w";
    	m_Html2Char[88] = "x";
    	m_Html2Char[89] = "y";	//121
    	m_Html2Char[90] = "z";
    	m_Html2Char[91] = "{";
    	m_Html2Char[92] = "|";
    	m_Html2Char[93] = "}";
    	m_Html2Char[94] = "~";	//126
    	
    	
    	return m_Html2Char;
    }
845189
public static Charset getStringEncodingCharset() {
		if (currentStringEncoding == null) {
			final String value = JanusConfig.getSystemProperty(BYTE_ARRAY_STRING_CHARSET_NAME, null);
			if (value != null) {
				try {
					currentStringEncoding = Charset.forName(value);
					if (currentStringEncoding == null) {
						currentStringEncoding = BYTE_ARRAY_STRING_CHARSET_VALUE;
					}
				} catch (Throwable exception) {
					currentStringEncoding = BYTE_ARRAY_STRING_CHARSET_VALUE;
				}
			} else {
				currentStringEncoding = BYTE_ARRAY_STRING_CHARSET_VALUE;
			}
		}
		return currentStringEncoding;
	}
618579
public function getChar()
    {
        $char = fgetc($this->stream);
        if (!$this->_utf8_char) {
            return $char;
        }

        $c = ord($char);
        if ($c < 0x80) {
            return $char;
        }

        if ($c < 0xe0) {
            $n = 1;
        } elseif ($c < 0xf0) {
            $n = 2;
        } elseif ($c < 0xf8) {
            $n = 3;
        } else {
            throw new Horde_Stream_Exception('ERROR');
        }

        for ($i = 0; $i < $n; ++$i) {
            if (($c = fgetc($this->stream)) === false) {
                throw new Horde_Stream_Exception('ERROR');
            }
            $char .= $c;
        }

        return $char;
    }
1242452
protected function getHtmlBody()
    {
        $charset    = $this->isUtf8($this->body['text/html']) ? 'utf-8' : 'US-ASCII';
        $html       = str_replace("\r", '', trim($this->body['text/html']));

        $encoded = explode("\n", $this->quotedPrintableEncode($html));
        $body   = array();
        $body[] = 'Content-Type: text/html; charset='.$charset;
        $body[] = 'Content-Transfer-Encoding: quoted-printable'."\n";

        foreach ($encoded as $line) {
            $body[] = $line;
        }

        $body[] = null;
        $body[] = null;

        return $body;
    }
83242
def get_charset(html):
    
    regex = r'charset=([a-zA-Z0-9-]+)?'
    pattern = re.compile(regex, re.IGNORECASE)
    if len(pattern.findall(html)) == 0:
        return 'UTF-8'
    return pattern.findall(html)[0]
1067812
function parse_charset($charset) {
		$charset = trim(strtolower($charset));
		if (isset($this->synonyms[$charset])) {
			$charset = $this->synonyms[$charset];
		}

		return $charset;
	}
1338408
private Charset getCharset()
   {
      Charset result = m_charset;
      if (result == null)
      {
         // We default to CP1252 as this seems to be the most common encoding
         result = m_encoding == null ? CharsetHelper.CP1252 : Charset.forName(m_encoding);
      }
      return result;
   }
559835
public function setCharset($charset)
    {
        $prev = $this->charset;

        $charset = strtoupper($charset);
        $charset = null === $charset || 'UTF-8' === $charset || 'UTF8' === $charset ? 'CP1252' : $charset;

        $this->charset = $charset;

        return $prev;
    }
440858
function serialize($charset_encoding='')
		{
			// add check? slower, but helps to avoid recursion in serializing broken xmlrpcvals...
			//if (is_object($o) && (get_class($o) == 'xmlrpcval' || is_subclass_of($o, 'xmlrpcval')))
			//{
				reset($this->me);
				list($typ, $val) = each($this->me);
				return '<value>' . $this->serializedata($typ, $val, $charset_encoding) . "</value>\n";
			//}
		}
1250122
public static function htmlspecialchars_decode($value) {
		$value = str_replace('&gt;', '>', $value);
		$value = str_replace('&lt;', '<', $value);
		$value = str_replace('&quot;', '"', $value);
		$value = str_replace('&amp;', '&', $value);
		return $value;
	}
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;
    }
584138
public function getCharset() {
		if (!isset($this->charset)) {
			$numOfMatches = preg_match('/charset\s*=([^;]*)/', $this->getHeader('Content-Type'), $matches);
			if ($numOfMatches) {
				$this->charset = trim($matches[1]);
			} else {
				$this->charset = '';
			}
		}
		return $this->charset;
	}