Attempts to detect the charset that the html was sent in.

@return bool
542366
protected function detectCharset(): bool
    {
        // set the default
        $encode = new Encode;
        $encode->from($this->defaultCharset);
        $encode->to($this->defaultCharset);

        if ( ! is_null($this->options->enforceEncoding)) {
            //  they want to enforce the given encoding
            $encode->from($this->options->enforceEncoding);
            $encode->to($this->options->enforceEncoding);

            return false;
        }

        $meta = $this->root->find('meta[http-equiv=Content-Type]', 0);
        if (is_null($meta)) {
            // could not find meta tag
            $this->root->propagateEncoding($encode);

            return false;
        }
        $content = $meta->content;
        if (empty($content)) {
            // could not find content
            $this->root->propagateEncoding($encode);

            return false;
        }
        $matches = [];
        if (preg_match('/charset=(.+)/', $content, $matches)) {
            $encode->from(trim($matches[1]));
            $this->root->propagateEncoding($encode);

            return true;
        }

        // no charset found
        $this->root->propagateEncoding($encode);

        return false;
    }
421906
public function detectFormat()
    {
        $format = $this->detectFormatByHeader();
        if ($format === null) {
            $format = $this->detectFormatByContent((string) $this->getBody());
        }

        return $format;
    }
1166354
protected function parse_charset()
	{
		global $debug_object;

		$charset = null;

		if (function_exists('get_last_retrieve_url_contents_content_type'))
		{
			$contentTypeHeader = get_last_retrieve_url_contents_content_type();
			$success = preg_match('/charset=(.+)/', $contentTypeHeader, $matches);
			if ($success)
			{
				$charset = $matches[1];
				if (is_object($debug_object)) {$debug_object->debug_log(2, 'header content-type found charset of: ' . $charset);}
			}

		}

		if (empty($charset))
		{
			$el = $this->root->find('meta[http-equiv=Content-Type]',0,true);
			if (!empty($el))
			{
				$fullvalue = $el->content;
				if (is_object($debug_object)) {$debug_object->debug_log(2, 'meta content-type tag found' . $fullvalue);}

				if (!empty($fullvalue))
				{
					$success = preg_match('/charset=(.+)/i', $fullvalue, $matches);
					if ($success)
					{
						$charset = $matches[1];
					}
					else
					{
						// If there is a meta tag, and they don't specify the character set, research says that it's typically ISO-8859-1
						if (is_object($debug_object)) {$debug_object->debug_log(2, 'meta content-type tag couldn\'t be parsed. using iso-8859 default.');}
						$charset = 'ISO-8859-1';
					}
				}
			}
		}

		// If we couldn't find a charset above, then lets try to detect one based on the text we got...
		if (empty($charset))
		{
			// Use this in case mb_detect_charset isn't installed/loaded on this machine.
			$charset = false;
			if (function_exists('mb_detect_encoding'))
			{
				// Have php try to detect the encoding from the text given to us.
				$charset = mb_detect_encoding($this->root->plaintext . "ascii", $encoding_list = array( "UTF-8", "CP1252" ) );
				if (is_object($debug_object)) {$debug_object->debug_log(2, 'mb_detect found: ' . $charset);}
			}

			// and if this doesn't work...  then we need to just wrongheadedly assume it's UTF-8 so that we can move on - cause this will usually give us most of what we need...
			if ($charset === false)
			{
				if (is_object($debug_object)) {$debug_object->debug_log(2, 'since mb_detect failed - using default of utf-8');}
				$charset = 'UTF-8';
			}
		}

		// Since CP1252 is a superset, if we get one of it's subsets, we want it instead.
		if ((strtolower($charset) == strtolower('ISO-8859-1')) || (strtolower($charset) == strtolower('Latin1')) || (strtolower($charset) == strtolower('Latin-1')))
		{
			if (is_object($debug_object)) {$debug_object->debug_log(2, 'replacing ' . $charset . ' with CP1252 as its a superset');}
			$charset = 'CP1252';
		}

		if (is_object($debug_object)) {$debug_object->debug_log(1, 'EXIT - ' . $charset);}

		return $this->_charset = $charset;
	}
34297
public function getCharSet()
    {
        if ($this->_sCharSet == null) {
            $this->_sCharSet = \OxidEsales\Eshop\Core\Registry::getLang()->translateString('charset');
        }

        return $this->_sCharSet;
    }
1348739
public static function e() {
        if(!Config::$o->debug) return;
        $args = func_get_args();
        if (!headers_sent()) {
            header("Content-type: text/html; charset=utf-8");
        }
        foreach($args as $arg) {
            self::ex($arg,true);
        }
    }
1307646
public static function checkBrowserNetPositive()
    {
        if (stripos(self::$userAgentString, 'NetPositive') !== false) {
            $aresult = explode('/', stristr(self::$userAgentString, 'NetPositive'));
            if (isset($aresult[1])) {
                $aversion = explode(' ', $aresult[1]);
                self::$browser->setVersion(str_replace(array('(', ')', ';'), '', $aversion[0]));
            }
            self::$browser->setName(Browser::NETPOSITIVE);

            return true;
        }

        return false;
    }
116763
def charset(self, default='UTF-8'):
        
        if 'charset=' in self.content_type:
            return self.content_type.split('charset=')[-1].split(';')[0].strip()
        return default
399884
public function dlstatsSetLang()
	{
	    $array = \Environment::get('httpAcceptLanguage');

	    $this->_lang = str_replace('-', '_', $array[0]);
	     
	    if(empty($this->_lang) || strlen($this->_lang) < 2)
	    {
	        $this->_lang = 'unknown';
	    }
	    return true;
	}
476337
protected function acceptEncoding()
	{
		$encoding = false;

		if (!isset($_SERVER['HTTP_ACCEPT_ENCODING']))
		{
			return $encoding;
		}

		if (false !== strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'))
		{
			$encoding = 'gzip';
		}

		if (false !== strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'x-gzip'))
		{
			$encoding = 'x-gzip';
		}

		return $encoding;
	}
764128
def encoding(self) -> _Encoding:
        
        if self._encoding:
            return self._encoding

        # Scan meta tags for charset.
        if self._html:
            self._encoding = html_to_unicode(self.default_encoding, self._html)[0]
            # Fall back to requests' detected encoding if decode fails.
            try:
                self.raw_html.decode(self.encoding, errors='replace')
            except UnicodeDecodeError:
                self._encoding = self.default_encoding


        return self._encoding if self._encoding else self.default_encoding
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;
    }
816955
function isAllowedCharset( $charset )
    {
        $realCharset = eZCharsetInfo::realCharsetCode( $charset );
        $charsets = $this->allowedCharsets();
        foreach ( $charsets as $charsetName )
        {
            $realName = eZCharsetInfo::realCharsetCode( $charsetName );
            if ( $realName == $realCharset )
                return true;
        }
        return false;
    }
690721
public String html() {
        if (html != null) {
            return html;
        }

        if (content == null) {
            return null;
        }
        if (charset == null) {
            charset = CharsetDetector.guessEncoding(content());
        }
        try {
            html = new String(content, charset);
        } catch (UnsupportedEncodingException e) {
            LOG.info("Exception when decoding "+ key(),e);
            return null;
        }
        return html;
    }
347658
function GetCharSet()
	{
		//we will use ADO's builtin property charSet
		$this->charSet = @pg_client_encoding($this->_connectionID);
		if (!$this->charSet) {
			return false;
		} else {
			return $this->charSet;
		}
	}
1006782
function usedCharset()
    {
        $charset = $this->contentCharset();
        if ( $this->isAllowedCharset( $charset ) )
            return $charset;
        return $this->outputCharset();
    }
426051
public function getCharset()
    {
        return (isset(Yii::$app->charset) ? Yii::$app->charset : null) ?: mb_internal_encoding();
    }
529393
public function isHtml() {
		$ext = $this->_controller->request->param('ext');
		if (empty($ext)) {
			return true;
		}

		$prefers = $this->_controller->RequestHandler->prefers();
		if (empty($prefers)) {
			$prefers = 'html';
		}

		$responseMimeType = $this->_controller->response->getMimeType($prefers);
		if (!$responseMimeType) {
			return false;
		}

		return in_array('text/html', (array)$responseMimeType);
	}