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:
parent
a76c555bc1
commit
017ffb51fc
|
@ -199,7 +199,7 @@ function select($result, $dbh2 = null) {
|
||||||
if (!isset($val)) {
|
if (!isset($val)) {
|
||||||
$val = "<i>NULL</i>";
|
$val = "<i>NULL</i>";
|
||||||
} else {
|
} else {
|
||||||
if ($blobs[$key] && preg_match('~[\\x80-\\xFF]~', $val)) {
|
if ($blobs[$key] && !is_utf8($val)) {
|
||||||
$val = "<i>" . lang('%d byte(s)', strlen($val)) . "</i>";
|
$val = "<i>" . lang('%d byte(s)', strlen($val)) . "</i>";
|
||||||
} else {
|
} else {
|
||||||
$val = nl2br(htmlspecialchars($val));
|
$val = nl2br(htmlspecialchars($val));
|
||||||
|
@ -224,6 +224,10 @@ function select($result, $dbh2 = null) {
|
||||||
$result->free();
|
$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) {
|
function shorten_utf8($string, $length) {
|
||||||
preg_match("~^(.{0,$length})(.?)~su", $string, $match);
|
preg_match("~^(.{0,$length})(.?)~su", $string, $match);
|
||||||
return nl2br(htmlspecialchars($match[1])) . ($match[2] ? "<em>...</em>" : "");
|
return nl2br(htmlspecialchars($match[1])) . ($match[2] ? "<em>...</em>" : "");
|
||||||
|
|
|
@ -246,7 +246,7 @@ if (!$columns) {
|
||||||
foreach ($row as $key => $val) {
|
foreach ($row as $key => $val) {
|
||||||
if (!isset($val)) {
|
if (!isset($val)) {
|
||||||
$val = "<i>NULL</i>";
|
$val = "<i>NULL</i>";
|
||||||
} 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 = '<a href="' . htmlspecialchars($SELF) . 'download=' . urlencode($_GET["select"]) . '&field=' . urlencode($key) . '&' . $unique_idf . '">' . lang('%d byte(s)', strlen($val)) . '</a>';
|
$val = '<a href="' . htmlspecialchars($SELF) . 'download=' . urlencode($_GET["select"]) . '&field=' . urlencode($key) . '&' . $unique_idf . '">' . lang('%d byte(s)', strlen($val)) . '</a>';
|
||||||
} else {
|
} else {
|
||||||
if (intval($text_length) > 0 && preg_match('~blob|text~', $fields[$key]["type"])) {
|
if (intval($text_length) > 0 && preg_match('~blob|text~', $fields[$key]["type"])) {
|
||||||
|
|
Loading…
Reference in a new issue