给网站添加xml地图索引写法

使用php给网站添加xml地图索引写法

php 复制代码
<?php
$new_array = array();
function loopDir($dir,&$new_array,$modurl)
{
  $handle = opendir($dir);
  header("Content-Type:text/xml");
$data = '<?xml version="1.0" encoding="UTF-8"?>';
$data .= '<sitemapindex>';
  while(($file = readdir($handle))!== false ){
      $today=date('Y-m-d', time());
    if ($file != '.' &&$file != 'index.php' && $file != 'indexxml.php' && $file != '..'){
      if (filetype($dir.'/'.$file) != 'dir'){
          $modurl="http://www.nongpin88.com/sitemap/";
          $fileurl=$modurl."xml/".$file;
          $data .= '<sitemap>';
          $data .= '<loc>'.$fileurl.'</loc>';
$data .= '<lastmod>'.$today.'</lastmod>';
$data .= '<changefreq>always</changefreq>';
$data .= '<priority>0.9</priority>';
$data .= '<data><display></display></data>';
$data .= '</sitemap>';   
 
      }
      if (filetype($dir.'/'.$file) == 'dir'){
        loopDir($file,$new_array);
      }
    }
  }
  $data .= $item;
  $data .= '</sitemapindex>';
$data = str_replace('><', ">\n<", $data);
echo $data;
}
 
 
$dir = './';
loopDir($dir,$new_array,$modurl);
 
?>

演示地址:模块地图

相关推荐
独行soc3 小时前
2025年渗透测试面试题总结-百度面经(题目+回答)
运维·开发语言·经验分享·学习·面试·渗透测试·php
pengone5 小时前
PHP8.0版本导出excel失败
php·excel
Javis2119 小时前
【Linux高级全栈开发】2.1.2 事件驱动reactor的原理与实现
linux·运维·php
LYPHARD MELODY。1 天前
将 JSON 批量转换为 XML:深度解析与完整实现指南
xml·json
James. 常德 student1 天前
网络安全知识点
安全·web安全·php
玉笥寻珍1 天前
筑牢信息安全防线:涉密计算机与互联网隔离的理论实践与风险防控
开发语言·计算机网络·安全·计算机外设·php·安全架构·安全性测试
uwvwko1 天前
BUUCTF——web刷题第一页题解
android·前端·数据库·php·web·ctf
lsswear1 天前
php fiber 应用
开发语言·php
yyywoaini~1 天前
序列化和反序列化hadoop实现
hadoop·eclipse·php
kp000001 天前
PHP弱类型安全漏洞解析与防范指南
android·开发语言·安全·web安全·php·漏洞