From eb1319119a3ff757a1fef22d9f23c952081703eb Mon Sep 17 00:00:00 2001 From: qkqpttgf <45693631+qkqpttgf@users.noreply.github.com> Date: Fri, 18 Feb 2022 16:11:23 +0800 Subject: [PATCH] check txtfile charset --- common.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/common.php b/common.php index 177c5aa..41991b6 100644 --- a/common.php +++ b/common.php @@ -727,6 +727,19 @@ function sortConfig(&$arr) return $arr; } +function chkTxtCode($str) { + $code = array( + 'ASCII', + 'GBK', + 'UTF-8', + 'UTF-16', + ); + foreach ($code as $c) { + if ($str === iconv('UTF-8', $c, iconv($c, 'UTF-8', $str))) return $c; + } + return false; +} + function getconstStr($str) { global $constStr; @@ -2555,8 +2568,9 @@ function render_list($path = '', $files = []) if (strpos($html, '')) { //$tmp_content = get_content(spurlencode(path_format(urldecode($path)), '/'))['content']['body']; $tmp_content = $files['content']['body']; - if (strlen($tmp_content)==$files['size']) $html = str_replace('', htmlspecialchars($tmp_content), $html); - else $html = str_replace('', $files['size']<1024*1024?htmlspecialchars(curl('GET', $files['url'], '', [], 0, 1)['body']):"File too large: " . $files['size'] . " B.", $html); + //if (strlen($tmp_content)==$files['size']) + $html = str_replace('', htmlspecialchars($tmp_content), $html); + //else $html = str_replace('', $files['size']<1024*1024?htmlspecialchars(curl('GET', $files['url'], '', [], 0, 1)['body']):"File too large: " . $files['size'] . " B.", $html); } $html = str_replace('', getconstStr('FileNotSupport'), $html);