Superian Posted August 11, 2008 Share Posted August 11, 2008 I am trying to write a script that checks whether a string is valid UTF-8, but I have no idea where to start. Any ideas? Thanks! Link to comment https://forums.phpfreaks.com/topic/119163-help-with-filter/ Share on other sites More sharing options...
Superian Posted August 11, 2008 Author Share Posted August 11, 2008 How could I make this into one function instead of having to use two? <?php function check_plain($text) { return _validate_utf8($text) ? htmlspecialchars($text, ENT_QUOTES) : ''; } function _validate_utf8($text) { if (strlen($text) == 0) { return TRUE; } return (preg_match('/^./us', $text) == 1); } ?> Link to comment https://forums.phpfreaks.com/topic/119163-help-with-filter/#findComment-613628 Share on other sites More sharing options...
discomatt Posted August 11, 2008 Share Posted August 11, 2008 http://www.php.net/manual/en/function.mb-detect-encoding.php Link to comment https://forums.phpfreaks.com/topic/119163-help-with-filter/#findComment-613631 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.