Created
April 1, 2012 17:06
-
-
Save tom--/2277106 to your computer and use it in GitHub Desktop.
Utf-8 input handling functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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