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

演示地址:模块地图

相关推荐
BingoGo1 天前
2025 年 PHP 常见面试题整理以及对应答案和代码示例
后端·php
Bruce1232 天前
web专题之php代审(二)
php
BingoGo2 天前
PHP-FPM 深度调优指南 告别 502 错误,让你的 PHP 应用飞起来
后端·php
l1t2 天前
利用美团龙猫用libxml2编写XML转CSV文件C程序
xml·c语言·libxml2·解析器
亿坊电商3 天前
物联网领域中PHP框架的最佳选择有哪些?
物联网·struts·php
wuzuyu3653 天前
用php做一个简易的路由
php·路由
老六ip加速器3 天前
手机ip隔离方法
tcp/ip·智能手机·php
rockmelodies3 天前
【PHP7内核剖析】-1.3 FPM
php
真正的醒悟3 天前
上网管理行为-ISP路由部署
服务器·php·接口隔离原则
张晓~183399481214 天前
短视频矩阵源码-视频剪辑+AI智能体开发接入技术分享
c语言·c++·人工智能·矩阵·c#·php·音视频