mirror of
https://github.com/icecoder/ICEcoder.git
synced 2026-03-03 07:13:59 +01:00
Detect encoding and use that in if statement
Try to detect encoding type and check on it not being ASCII in if statement too
This commit is contained in:
@@ -53,6 +53,8 @@ function numClean($var) {
|
||||
|
||||
// returns a UTF8 based string with any UFT8 BOM removed
|
||||
function toUTF8noBOM($string,$message) {
|
||||
// Attempt to detect encoding
|
||||
$encType = mb_detect_encoding($string);
|
||||
// Get rid of any UTF-8 BOM
|
||||
$string = preg_replace('/\x{EF}\x{BB}\x{BF}/','',$string);
|
||||
// Test for any bad characters
|
||||
@@ -60,7 +62,7 @@ function toUTF8noBOM($string,$message) {
|
||||
$teststringBroken = utf8_decode($teststring);
|
||||
$teststringConverted = iconv("UTF-8", "UTF-8//IGNORE", $teststringBroken);
|
||||
// If we have a matching length, UTF8 encode it
|
||||
if (strlen($teststringConverted) == strlen($teststringBroken)) {
|
||||
if ($encType != "ASCII" && strlen($teststringConverted) == strlen($teststringBroken)) {
|
||||
$string = utf8_encode($string);
|
||||
if ($message) {
|
||||
echo "<script>top.ICEcoder.message('Your document doesn\'t appear to be in UTF-8 encoding so has been converted.');</script>";
|
||||
|
||||
Reference in New Issue
Block a user