I can’t say I can rely on mb_detect_encoding()
. I had some freaky false positives a while back.
The most universal way I found to work well in every case was:
if (preg_match('!!u', $string))
{
// This is UTF-8
}
else
{
// Definitely not UTF-8
}
More Related Contents:
- Detect encoding and make everything UTF-8
- How can I write a file in UTF-8 format?
- Convert utf8-characters to iso-88591 and back in PHP
- PHP json encode – Malformed UTF-8 characters, possibly incorrectly encoded [duplicate]
- How to handle user input of invalid UTF-8 characters
- json_encode() non utf-8 strings?
- How can I detect a malformed UTF-8 string in PHP?
- PHP messing with HTML Charset Encoding
- utf-8 special characters not displaying [duplicate]
- Ensuring valid UTF-8 in PHP
- UTF8 Filenames in PHP and Different Unicode Encodings
- How to decode Unicode escape sequences like “\u00ed” to proper UTF-8 encoded characters?
- How can I output a UTF-8 CSV in PHP that Excel will read properly?
- How to remove multiple UTF-8 BOM sequences
- PHP: Convert any string to UTF-8 without knowing the original character set, or at least try
- MySQL and PHP: UTF-8 with Cyrillic characters [duplicate]
- Fixing broken UTF-8 encoding
- can I get the unicode value of a character or vise versa with php?
- Getting data with UTF-8 charset from MSSQL server using PHP FreeTDS extension
- is PHP str_word_count() multibyte safe?
- decode a quoted printable message in php
- ‘Malformed UTF-8 characters, possibly incorrectly encoded’ in Laravel
- strlen() and UTF-8 encoding
- UTF-8 safe equivalent of ord or charCodeAt() in PHP
- Working with GD ( imagettftext() ) and UTF-8 characters
- Turkish characters are not displayed correctly [duplicate]
- Is it possible to preserve plus signs in PHP $_GET vars without encoding?
- UTF-8 not working in HTML forms
- Decoding numeric html entities via PHP
- Trim unicode whitespace in PHP