给网站添加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);
 
?>

演示地址:模块地图

相关推荐
m0_380743876 小时前
给 Claude API 调用补上超时重试和错误分类
开发语言·人工智能·php
yuewell_ai8 小时前
机器人调度通讯怎么设计才不会被网络抖动瘫痪
网络·机器人·php
FfHUCisI18 小时前
GMP 调度器:Go 并发的心脏是如何跳动的
开发语言·golang·php
星云API技术支持19 小时前
企业微信二次开发外部群:群聊数据与联系人信息如何建立关联
数据库·php·企业微信
spencer_tseng2 天前
[j2cache ehcache.xml]/tmp/.ehcache-diskstore.lock (Permission denied)
xml·linux·python·ehcache·[j2cache
sbjdhjd2 天前
PHP eval 型 RCE:flag 正则过滤与通配符绕过实操 | 01
安全·web安全·网络安全·开源·系统安全·php·网络攻击模型
qetfw2 天前
Debian Nginx + PHP-FPM 配置:FastCGI、站点目录与访问验证
linux·nginx·debian·php
啊阿狸不会拉杆2 天前
《计算机网络-自顶向下方法》3.6 拥塞控制原理 读书笔记
计算机网络·智能路由器·php
郑州光合科技余经理2 天前
本地生活服务系统:成品模块和定制接口怎么划界
java·前端·人工智能·后端·系统架构·php·ai编程
LorryJovens2 天前
【LAAP科研】CEN因果等价网络理论---从双缝干涉到因果等价
开发语言·php