From 466e8f197fdd9931601a79a40aac3d7a00f44091 Mon Sep 17 00:00:00 2001 From: LMR <59361885@qq.com> Date: Wed, 22 May 2024 15:22:55 +0800 Subject: [PATCH] todo: list_info_by_keys --- application/controllers/infofix.php | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/application/controllers/infofix.php b/application/controllers/infofix.php index 79f6b570..60e27149 100644 --- a/application/controllers/infofix.php +++ b/application/controllers/infofix.php @@ -16,13 +16,12 @@ class infofix extends CI_Controller function list_info_by_keys() { // 防止超时 - header('Access-Control-Allow-Origin: *'); set_time_limit(0); // json参数 $site = $this->input->get_post('site'); $keys = $this->input->get_post('keys'); - $keyArr = json_decode($keys, true); + $keyArr = explode(',', $keys); // 容错 if (empty($site) || empty($keys) || strpos($keys, '/') === false) { @@ -31,7 +30,7 @@ class infofix extends CI_Controller } // 关键字信息 - $rs = $this->Information_model->list_by_keywords($site, $keys); + $rs = $this->Information_model->list_by_keywords($site, $keyArr); // 调整数据 foreach ($rs as $info) { @@ -42,11 +41,11 @@ class infofix extends CI_Controller $sub_url = $info->ic_url == $key ? $info->ic_url : ''; $pos_content = 0; - $pos_content = stripos($info->ic_content, $key); + $pos_content = mb_stripos($info->ic_content, $key); $sub_content = array(); while ($pos_content) { - array_push($sub_content, '[...' . mb_substr($info->ic_content, $pos_content - 20, strlen($key) + 20 * 2) . '...]'); - $pos_content = stripos($info->ic_content, $key, $pos_content + strlen($key)); + array_push($sub_content, '[...' . mb_substr($info->ic_content, $pos_content - 20, mb_strlen($key) + 20 * 2) . '...]'); + $pos_content = mb_stripos($info->ic_content, $key, $pos_content + mb_strlen($key)); } if ($sub_url != '' || count($sub_content) != 0) { @@ -57,10 +56,23 @@ class infofix extends CI_Controller } echo json_encode($rs); - echo json_last_error_msg(); } + function update_info_by_keys() + { + // json参数 + $site = $this->input->get_post('site'); + $keys = $this->input->get_post('keys'); + $keyArr = explode(',', $keys); + + // 容错 + if (empty($site) || empty($keys) || strpos($keys, '/') === false) { + echo json_encode(array()); + return false; + } + + } } //end of infofix