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

演示地址:模块地图

相关推荐
TE-茶叶蛋5 小时前
ThinkPHP入门
php
TE-茶叶蛋6 小时前
结合登录页-PHP基础知识点解析
android·开发语言·php
流觞 无依7 小时前
DedeCMS plus/comment.php 评论 XSS/注入(XSS、SQL注入)修复教程
sql·php·xss
cyber_两只龙宝9 小时前
【Nginx】Nginx实现FastCGI详解
linux·运维·nginx·云原生·php·memcached·fastcgi
dog2509 小时前
卡瓦列里积分赏析
开发语言·php
5G丶9 小时前
ThinkPHP 集群部署完整指南
数据库·php
流觞 无依9 小时前
DedeCMS plus/recommend.php SQL注入漏洞修复教程
sql·php
流觞 无依10 小时前
DedeCMS plus/list.php 参数注入(SQL注入)修复教程
sql·安全·php
软件开发技术10 小时前
最新网络游戏账户交易平台系统源码 全开源版本 全新UI 自适应移动端
php