网站seo检测工具 (网站SEO检测报告)

杭州桑拿 05-10 阅读:29 评论:0
html loadHTML($html);// 获取页面标题$title = $dom->getElementsByTagName('title')->item(0)->nodeValue;// 获取元描述$meta_description = $dom->getElementsByTagName('meta')->item(0)->getAttribute('content');// 获取内容$content = $dom->getElementsByTagName('body')->item(0)->nodeValue;// 检测关键词$keywords = array();$keywords_tag = $dom->getElementsByTagName('meta')->item(1)->getAttribute('content'); if (!empty($keywords_tag)) {$keywords = explode(',', $keywords_tag);}// 检测标题长度$title_length = strlen($title);// 检测元描述长度$meta_description_length = strlen($meta_description);// 检测内容长度$content_length = strlen($content);// 检测外部链接数量$external_links = $dom->getElementsByTagName('a');$external_link_count = 0;foreach ($external_links as $link) {if (strpos($link->getAttribute('href'), $url) === false) {$external_link_count++;}}// 检测图像数量$images = $dom->getElementsByTagName('img');$image_count = $images->length;// 检测标题中是否包含关键词$title_contains_keyword = false;foreach ($keywords as $keyword) {if (strpos($title, $keyword) !== false) {$title_contains_keyword = true;}}// 检测元描述中是否包含关键词$meta_description_contains_keyword = false;foreach ($keywords as $keyword) {if (strpos($meta_description, $keyword) !== false) {$meta_description_contains_keyword = true;}}// 检测内容中是否包含关键词$content_contains_keyword = false;foreach ($keywords as $keyword) {if (strpos($content, $keyword) !== false) {$content_contains_keyword = true;}}// 生成报告echo '
    ';echo '
  • 页面标题: ' . $title . '
  • ';echo '
  • 页面标题长度: ' . $title_length . '
  • ';echo ' 网站seo检测工具 (网站SEO检测报告)
  • 页面标题是否包含关键词: ' . ($title_contains_keyword ? '是' : '否') . '
  • ';echo '
  • 元描述: ' . $meta_description . '
  • ';echo '
  • 元描述长度: ' . $meta_description_length . '
  • ';echo '
  • 元描述是否包含关键词: ' . ($meta_description_contains_keyword ? '是' : '否') . '
  • ';echo '
  • 内容长度: ' . $content_length . '
  • ';echo '
  • 内容是否包含关键词: ' . ($content_contains_keyword ? '是' : '否') . '
  • ';echo '
  • 外部链接数量: ' . $external_link_count . '
  • ';echo '
  • 图像数量: ' . $image_count . '
  • ';echo '
';}// 关闭 cURL 会话curl_close($ch);?>
版权声明

本文仅代表作者观点,不代表杭州桑拿立场。
本文系作者授权发表,未经许可,不得转载。