- <?php
- /**
- * 获取关键字接口
- */
- defined('IN_PHPCMS') or exit('No permission resources.');
- //自带接口以及无法使用
- //define('API_URL_GET_KEYWORDS', 'http://tool.phpcms.cn/api/get_keywords.php');
- define('API_URL_GET_KEYWORDS', 'http://zhannei.baidu.com/api/customsearch/keywords');
- $number = intval($_GET['number']);
- $data = $_POST['data'];
- echo get_keywords($data, $number);
- function get_keywords($data, $number = 3) {
- $data = trim(strip_tags($data));
- if(empty($data)) return '';
- //$http->post(API_URL_GET_KEYWORDS, array('siteurl'=>SITE_URL, 'charset'=>CHARSET, 'data'=>$data, 'number'=>$number));
- $rs = pc_file_get_contents(API_URL_GET_KEYWORDS.'?title=' . urlencode($data), 3);
- if (!$rs) {
- return '';
- }
- $data = json_decode($rs, true);
- if (!$data || empty($data['result']['res']['keyword_list'])) {
- return '';
- }
- if (count($data['result']['res']['keyword_list']) > $number) {
- $data['result']['res']['keyword_list'] = array_slice($data['result']['res']['keyword_list'], 0, $number);
- }
- if (CHARSET != 'utf-8') {
- return iconv('utf-8', 'gbk', implode(' ', $data['result']['res']['keyword_list']));
- } else {
- return implode(' ', $data['result']['res']['keyword_list']);
- }
- }
- ?>
希望以上内容对你有所帮助!如果还有其他问题,请随时提问。 各类知识收集 拥有多年CMS企业建站经验,对 lecms, classcms, fastadmin, pbootcms, phpcms, eyoucms, yzmcms, PHP, xunruicms, jizhicms, dedecms, wordpress, hkcms, yzncms, 等各类cms的相互转化,程序开发,网站制作,bug修复,程序杀毒,插件定制都可以提供最佳解决方案。