From cb5fe75fb999e98f60c3b517c442ab843b3ad227 Mon Sep 17 00:00:00 2001 From: LyLme Date: Mon, 4 Apr 2022 11:12:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E9=9D=9EUTF-8=E7=BC=96?= =?UTF-8?q?=E7=A0=81=E8=87=AA=E5=8A=A8=E8=8E=B7=E5=8F=96=E4=B9=B1=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apply/index.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/apply/index.php b/apply/index.php index 67eefd6..388398b 100644 --- a/apply/index.php +++ b/apply/index.php @@ -10,16 +10,22 @@ if(!empty($url = isset($_GET['url']) ? $_GET['url'] : null)) { ) ); $contents = @file_get_contents("compress.zlib://".$url, false, stream_context_create($opts)); - preg_match('/(.*?)<\/title>/is',$contents,$title); - preg_match('/<link rel=".*?icon" * href="(.*?)".*?>/is', $contents,$icon); - + preg_match('/<title>(.*?)<\/title>/is',$contents,$title); // 获取网站标题 + preg_match('/<link rel=".*?icon" * href="(.*?)".*?>/is', $contents,$icon); // 获取网站icon + preg_match('/<meta.+?charset=[^\w]?([-\w]+)/i', $contents,$charset); //获取网站编码 + $get_heads['charset']=$charset[1]; $get_heads['title'] = str_replace("'","\"",preg_replace("/\s/","",$title[1])); $get_heads['icon'] = get_urlpath(preg_replace("/\s/","",$icon[1]),$url); + if(strtolower($get_heads['charset'])!="uft-8"){ + // 将非UTF-8编码转换 + $get_heads['title'] = iconv($get_heads['charset'], "UTF-8",$get_heads['title']); + $get_heads['icon'] = iconv($get_heads['charset'], "UTF-8",$get_heads['icon']); + } return $get_heads; } $head = get_head($url); header('Content-Type:application/json'); - exit("{'title': '".$head['title']."', 'icon': '".$head['icon']."'}"); + exit("{'title': '".$head['title']."', 'icon': '".$head['icon']."','charset': '".$head['charset']."'}"); } $grouplists =$DB->query("SELECT * FROM `lylme_groups`"); if(isset($_REQUEST['authcode'])) { @@ -214,7 +220,8 @@ if(isset($_REQUEST['authcode'])) { <label>网站图标:</label> <textarea type="text" id="icon" class="form-control" name="icon" placeholder="如:https://hao.lylme.com/assets/img/logo.png"></textarea> <span class="mdi mdi-emoticon form-control-feedback" aria-hidden="true"></span> - <small class="help-block">填写图标的<code>URL</code>地址,如:<code>http://www.xxx.com/img/logo.png</code></small> + <small class="help-block">填写图标的<code>URL</code>地址,如:<code>http://www.xxx.com/img/logo.png</code><br> + 部分网站无法自动获取,请手动填写</small> </div> </div> <!--<div class="form-group has-feedback feedback-left row">-->