Skip to content

Instantly share code, notes, and snippets.

@tom--
Created April 1, 2012 17:06
Show Gist options
  • Save tom--/2277106 to your computer and use it in GitHub Desktop.
Save tom--/2277106 to your computer and use it in GitHub Desktop.
Utf-8 input handling functions
<?php
function clean_utf8($s) {
return iconv('UTF-8', 'UTF-8//IGNORE', $s);
}
function check_utf8($s) {
return mb_check_encoding($s, 'UTF-8');
}
function clean_input(&$a) {
if (isset($a) && is_array($a) && !empty($a))
foreach ($a as $k => &$v)
clean_input($v);
elseif (is_string($a) && !mb_check_encoding($a, 'UTF-8'))
$a = iconv('UTF-8', 'UTF-8//IGNORE', $a);
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment