Skip to content

Instantly share code, notes, and snippets.

View matschundbrei's full-sized avatar

Jan 'Maub' Kapellen matschundbrei

View GitHub Profile
@matschundbrei
matschundbrei / scheiss-encoding.php
Last active September 5, 2017 14:02
php functions based on mbstring/preg_match that will detect utf8 and fix German encoding if no utf8 is detected.
<?php
//SCHEISS ENCODING!!!
//via: http://php.net/manual/de/function.mb-detect-encoding.php#68607
function detectUTF8($string){
return preg_match('%(?:
[\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
|\xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
|\xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
|\xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3