From d61ca06a4a42c2cfe2c47fbe1a8d1647c354d056 Mon Sep 17 00:00:00 2001 From: LiaoYijun Date: Thu, 2 Aug 2018 10:57:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=B7=9F=E8=B8=AA=E9=93=BE?= =?UTF-8?q?=E6=8E=A5nofollow=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/controllers/welcome.php | 32 +++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/application/controllers/welcome.php b/application/controllers/welcome.php index 73dc33b3..65db0a8a 100644 --- a/application/controllers/welcome.php +++ b/application/controllers/welcome.php @@ -195,13 +195,41 @@ class Welcome extends CI_Controller { // )); } - public function count_redirect_nofllow() { + public function count_redirect_nofollow() { $include_redirece_info = $this->Information_model->search_all_text('.htm&t=78002', 2000); echo 'count: '.count($include_redirece_info).'
'; + $nofollow_count = 0; + $htm_doc = new DOMDocument(); + $htm_doc->encoding='UTF-8'; + libxml_use_internal_errors(true); + $htm_doc->strictErrorChecking = false; foreach ($include_redirece_info as $info) { - echo '('.$info->ic_id.','.$info->is_id.')'.$info->ic_url.' | '.$info->ic_title.'
'; + $htm_doc->loadHTML( + mb_convert_encoding($info->ic_content, 'HTML-ENTITIES', 'UTF-8')); + $htm_doc->normalizeDocument(); + $anchor_list = $htm_doc->getElementsByTagName('a'); + foreach ($anchor_list as $anchor) { + $a_href = $anchor->getAttribute('href'); + $a_rel = $anchor->getAttribute('rel'); + + $match_result = array(); + preg_match('/.*.htm&t=78002$/', $a_href, $match_result); + $result_count = count($match_result); + if ($result_count > 0 && $a_rel != 'nofollow') { + $nofollow_count = $nofollow_count + 1; + echo $info->ic_url.' | '.'('.$info->ic_id.','.$info->is_id.')'.'
'; + echo 'a.href: '.$a_href.'; rel: '.$a_rel.'
'; + var_dump($match_result); + } + // if ($result_count == 2) { + // $result = '//www.chinahighlights.com'.$match_result[1]; + // $anchor->setAttribute('href', $result); + // echo $result.'
'; + // } + } } + echo 'nofollow_count: '.$nofollow_count.'
'; } public function count_http_of_href() {