diff --git a/application/controllers/infofix.php b/application/controllers/infofix.php index 4e0e59e1..797e34d2 100644 --- a/application/controllers/infofix.php +++ b/application/controllers/infofix.php @@ -198,6 +198,55 @@ class infofix extends CI_Controller { } + /** + * 根据关键词移除信息内容中的链接 + * @param string $html + * @param string $keys 字符串,每个key用@分隔 + * @return string + */ + function removeLinksByKeys($html, $keys) { + // 拆分$keys为数组 + $keysArr = explode('@', $keys); + // 遍历每个key,依次移除包含该key的a标签 + foreach ($keysArr as $key) { + if (empty($key)) { + continue; + } + + $pattern = '/]*href=["\']([^"\']*' . preg_quote($key, '/') . '[^"\']*)["\'][^>]*>(.*?)<\/a>/i'; + $html = preg_replace($pattern, '$2', $html); + } + // 替换为纯文本内容(第二个捕获组) + return $html; + } + + /** + * 根据ic_id和key更新信息内容 + */ + public function update_info_by_icid_keys() { + $ic_id = $this->input->get_post('ic_id'); + $keys = $this->input->get_post('keys'); + + // 容错 + if (empty($ic_id) || empty($keys)) { + echo json_encode(['err' => 'para_参数错误']); + return false; + } + // echo $ic_id . ' - ' . $keys . "\n"; + + // 更新信息 + $ic = $this->infoContents_model->get_ic_contents2($ic_id); + // print_r($ic); + + if (! empty($ic)) { + $ic->ic_content = $this->removeLinksByKeys($ic->ic_content, $keys); + $this->infoContents_model->force_update($ic_id, $ic->ic_content); + echo json_encode(['status' => 1]); + } else { + echo json_encode(['err' => 'icid_' . $ic_id . '_未找到信息内容']); + } + } + /** * 无条件获取信息内容 * @param mixed $ic_id