HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/PvdBoogaard/indoorski.nl/backup/oude-site/cms/lib/functions.utf8.php
<?php

/**
 * IsUtf8
 * Function to detect if a string is in UTF-8 or not
 *
 * @param string $string String to test for character encoding.
 * @return boolean True if the string is in utf-8, false otherwise
 */
function IsUtf8($string)
{
	$string_utf8 = utf8_encode($string);
	if( strpos($string_utf8,"\x9F",0) !== false ){ // "\x9F" is ALT+159
		return true;  // the original string was utf8
	}else{
		return false; // otherwise
	}
}

if(!function_exists('html_entity_decode_utf8')){
	function html_entity_decode_utf8($string)
	{
		static $trans_tbl;

		// replace numeric entities
		$string = preg_replace('~&#x0*([0-9a-f]+);~ei', 'code2utf(hexdec("\\1"))', $string);
		$string = preg_replace('~&#0*([0-9]+);~e', 'code2utf(\\1)', $string);

		// replace literal entities
		if (!isset($trans_tbl))
		{
			$trans_tbl = array();

			foreach (get_html_translation_table(HTML_ENTITIES) as $val=>$key)
				$trans_tbl[$key] = utf8_encode($val);
		}

		return strtr($string, $trans_tbl);
	}
}

/**
* utf8_encode_all
* This structure encodes the difference between ISO-8859-1 and Windows-1252,
* as a map from the UTF-8 encoding of some ISO-8859-1 control characters to
* the UTF-8 encoding of the non-control characters that Windows-1252 places
* at the equivalent code points.
*
* @param String $str String to convert
* @author Aidan Kehoe <php-manual@parhasard.net> (code from http://php.net/utf8_encode)
*/

function utf8_encode_all($str) {
	$cp1252_map = array(
	"\xc2\x80" => "\xe2\x82\xac", /* EURO SIGN */
	"\xc2\x82" => "\xe2\x80\x9a", /* SINGLE LOW-9 QUOTATION MARK */
	"\xc2\x83" => "\xc6\x92",     /* LATIN SMALL LETTER F WITH HOOK */
	"\xc2\x84" => "\xe2\x80\x9e", /* DOUBLE LOW-9 QUOTATION MARK */
	"\xc2\x85" => "\xe2\x80\xa6", /* HORIZONTAL ELLIPSIS */
	"\xc2\x86" => "\xe2\x80\xa0", /* DAGGER */
	"\xc2\x87" => "\xe2\x80\xa1", /* DOUBLE DAGGER */
	"\xc2\x88" => "\xcb\x86",     /* MODIFIER LETTER CIRCUMFLEX ACCENT */
	"\xc2\x89" => "\xe2\x80\xb0", /* PER MILLE SIGN */
	"\xc2\x8a" => "\xc5\xa0",     /* LATIN CAPITAL LETTER S WITH CARON */
	"\xc2\x8b" => "\xe2\x80\xb9", /* SINGLE LEFT-POINTING ANGLE QUOTATION */
	"\xc2\x8c" => "\xc5\x92",     /* LATIN CAPITAL LIGATURE OE */
	"\xc2\x8e" => "\xc5\xbd",     /* LATIN CAPITAL LETTER Z WITH CARON */
	"\xc2\x91" => "\xe2\x80\x98", /* LEFT SINGLE QUOTATION MARK */
	"\xc2\x92" => "\xe2\x80\x99", /* RIGHT SINGLE QUOTATION MARK */
	"\xc2\x93" => "\xe2\x80\x9c", /* LEFT DOUBLE QUOTATION MARK */
	"\xc2\x94" => "\xe2\x80\x9d", /* RIGHT DOUBLE QUOTATION MARK */
	"\xc2\x95" => "\xe2\x80\xa2", /* BULLET */
	"\xc2\x96" => "\xe2\x80\x93", /* EN DASH */
	"\xc2\x97" => "\xe2\x80\x94", /* EM DASH */

	"\xc2\x98" => "\xcb\x9c",     /* SMALL TILDE */
	"\xc2\x99" => "\xe2\x84\xa2", /* TRADE MARK SIGN */
	"\xc2\x9a" => "\xc5\xa1",     /* LATIN SMALL LETTER S WITH CARON */
	"\xc2\x9b" => "\xe2\x80\xba", /* SINGLE RIGHT-POINTING ANGLE QUOTATION*/
	"\xc2\x9c" => "\xc5\x93",     /* LATIN SMALL LIGATURE OE */
	"\xc2\x9e" => "\xc5\xbe",     /* LATIN SMALL LETTER Z WITH CARON */
	"\xc2\x9f" => "\xc5\xb8"      /* LATIN CAPITAL LETTER Y WITH DIAERESIS*/
	);
	return strtr(utf8_encode($str), $cp1252_map);
}

if(!function_exists('code2utf')){
	// Returns the utf string corresponding to the unicode value (from php.net, courtesy - romans@void.lv)
	function code2utf($num)
	{
		if ($num < 128) return chr($num);
		if ($num < 2048) return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
		if ($num < 65536) return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
		if ($num < 2097152) return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
		return '';
	}
}