Better UTF-8 detection

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@664 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
jakubvrana
2009-06-11 05:05:35 +00:00
parent a76c555bc1
commit 017ffb51fc
2 changed files with 6 additions and 2 deletions

View File

@@ -199,7 +199,7 @@ function select($result, $dbh2 = null) {
if (!isset($val)) {
$val = "<i>NULL</i>";
} else {
if ($blobs[$key] && preg_match('~[\\x80-\\xFF]~', $val)) {
if ($blobs[$key] && !is_utf8($val)) {
$val = "<i>" . lang('%d byte(s)', strlen($val)) . "</i>";
} 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] ? "<em>...</em>" : "");