diff --git a/include/functions.inc.php b/include/functions.inc.php index 42df67d0..1dc34933 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -199,7 +199,7 @@ function select($result, $dbh2 = null) { if (!isset($val)) { $val = "NULL"; } else { - if ($blobs[$key] && preg_match('~[\\x80-\\xFF]~', $val)) { + if ($blobs[$key] && !is_utf8($val)) { $val = "" . lang('%d byte(s)', strlen($val)) . ""; } else { $val = nl2br(htmlspecialchars($val)); @@ -224,6 +224,10 @@ function select($result, $dbh2 = null) { $result->free(); } +function is_utf8($val) { + return (preg_match('~~u', $val) && !preg_match('~[\\0-\\x8\\xB\\xC\\xE-\\x1F]~', $val)); +} + function shorten_utf8($string, $length) { preg_match("~^(.{0,$length})(.?)~su", $string, $match); return nl2br(htmlspecialchars($match[1])) . ($match[2] ? "..." : ""); diff --git a/select.inc.php b/select.inc.php index 0fab31a4..59556f2d 100644 --- a/select.inc.php +++ b/select.inc.php @@ -246,7 +246,7 @@ if (!$columns) { foreach ($row as $key => $val) { if (!isset($val)) { $val = "NULL"; - } elseif (preg_match('~blob|binary~', $fields[$key]["type"]) && preg_match('~[\\0-\\x8\\xb\\xc\\xe-\\x1F\\x80-\\xFF]~', $val)) { + } elseif (preg_match('~blob|binary~', $fields[$key]["type"]) && !is_utf8($val)) { $val = '' . lang('%d byte(s)', strlen($val)) . ''; } else { if (intval($text_length) > 0 && preg_match('~blob|text~', $fields[$key]["type"])) {