Skip to content

Instantly share code, notes, and snippets.

@inogo
Created December 11, 2011 13:38
Show Gist options
  • Save inogo/1460667 to your computer and use it in GitHub Desktop.
Save inogo/1460667 to your computer and use it in GitHub Desktop.
simple encoding detection
<?php
function detect_encoding($string)
{
foreach (array('UTF-8', 'Windows-1251') as $enc) {
$sample = @iconv($enc, $enc, $string);
if (md5($sample) == md5($string))
return $enc;
}
return false;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment