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

演示地址:模块地图

相关推荐
寺中人17 小时前
Xshell 完全入门指南:从安装到实战,远程连接+文件传输+会话管理全拆解
git·ssh·github·php·远程连接·xshell·运维工具
hengdonghui19 小时前
Writeup 4 津门杯 2021 Web hate_php
php·web·ctf·通配符
现任明教教主~20 小时前
企业查询系统源码
php
派小心.20 小时前
页面关闭前埋点丢失:sendBeacon验收
开发语言·php
我就是不信21 小时前
TCP 套接字中的 I/O 缓冲:原理、机制与调优实践
网络·tcp/ip·php
张小姐的猫1 天前
【Linux】网络编程 —— 五种IO模型
linux·运维·服务器·网络·c++·人工智能·php
ESDWAN1 天前
跨境电商网络专线怎么选?从带宽、延迟到SD-WAN部署与带宽管理的完整落地指南
开发语言·网络·php
qetfw1 天前
Debian iSCSI Target 与 open-iscsi:LVM 后端、ACL 与客户端验证
linux·服务器·debian·php
刘胡子大叔1 天前
PHP 扩展加载失败
php
一木 之林1 天前
阿里云百炼与通义千问接入
开发语言·php