sitemap站点地图

<?php
$root = ‘/home/webroot/cmsnew.com/html/hk‘; //当前目录
$dir_array = array(‘news‘,‘stocks‘, ‘shhkc‘, ‘warrants‘, ‘ipo‘, ‘ashares‘, ‘futures‘, ‘forex‘, ‘commodity‘, ‘events‘);
//if(isset($argv) && count($argv)!==0){
//    $dir_array = $argv[1];
//}

list_file($root,$dir_array);

function list_file($root,$dir_array)
{
    foreach ($dir_array as $dir) {//遍历
        $file_location = $root .‘/‘. $dir;//生成路径
        //$file = ‘/home/xiongx/sitemap‘ . ‘/‘ .$dir. ‘.xml‘;
        //todo 修改为正式要生成的地址
        $file = ‘/home/webroot/cmsnew.com/html/hk/sitemap‘ . ‘/‘ .$dir. ‘.xml‘;
        if(file_exists($file)){
            @unlink($file);
            $realname = basename($file,‘.xml‘);
            for($i=1;$i<=9;$i++){
                $newname = $realname . $i;
                @unlink(str_replace($realname,$newname,$file));
            }
        }
        file_put_contents($file,"<urlset>",FILE_APPEND);
        add_site($file_location,$file);
        file_put_contents($file,"</urlset>",FILE_APPEND);
    }
}
function add_site($dir,&$file){
    if(preg_match(‘/^[a-z]{1,30}$/i‘,substr($dir,strripos($dir,‘/‘)+1))) {
        $content = "<url><loc>" . "http://www.cnfol.hk/" . str_replace(‘/home/webroot/cmsnew.com/html/hk/‘, ‘‘, $dir) . "</loc></url>";
        file_put_contents($file,$content,FILE_APPEND);
    }
    $dir_arr = scandir($dir);
    array_shift($dir_arr);
    array_shift($dir_arr);
    foreach($dir_arr as $v){
        if(is_dir($dir . ‘/‘ . $v)){
            add_site($dir . ‘/‘ . $v,$file);
        }elseif(is_file($dir . ‘/‘ . $v) && preg_match(‘/(\.shtml)$/i‘,$dir . ‘/‘ . $v)){
            $content = "<url><loc>" . "http://www.cnfol.hk/" . str_replace(‘/home/webroot/cmsnew.com/html/hk/‘, ‘‘, $dir. ‘/‘ . $v) . "</loc></url>";
            file_put_contents($file,$content,FILE_APPEND);
            $filesize=abs(filesize($file));
            if($filesize>5120000){
                file_put_contents($file,"</urlset>",FILE_APPEND);
                $realname = basename($file,‘.xml‘);
                $n = (int)$realname + 1 ;
                $newname = $realname . $n;
                $file = str_replace($realname,$newname,$file);
                file_put_contents($file,"<urlset>",FILE_APPEND);
            }
        }
    }

}

  

时间: 2024-08-10 00:06:34

sitemap站点地图的相关文章

Django:之Sitemap站点地图、通用视图和上下文渲染器

Django中自带了sitemap框架,用来生成xml文件 Django sitemap演示: sitemap很重要,可以用来通知搜索引擎页面的地址,页面的重要性,帮助站点得到比较好的收录. 开启sitemap功能的步骤 settings.py文件中django.contrib.sitemaps和django.contrib.sites要在INSTALL_APPS中 INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth',

[Asp.net]站点地图SiteMap

引言 在项目中发现使用站点地图的控件,之前没总结过这方面的东西,就写了一个demo测试了一下,这里记录一下,算是总结吧. Web.sitemap 1 <?xml version="1.0" encoding="utf-8" ?> 2 <siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" > 3 <siteMapNode url=&q

php生成百度站点地图sitemap.xml

<?php header("Content-type:text/html;charset=utf-8"); //php生成百度站点地图sitemap.xml //http://www.baidu.com/search/sitemaptools_help.html include("../config.inc.php"); mysql_connect($CFG['db_host'] ,$CFG['db_user'],$CFG['db_pass']) or die

dt7.0中加入站点地图(sitemap.txt)功能输出

为了百度seo需要,看百度站长平台可以提交sitemap.txt地图,顺便加了这个功能,供广大爱好者学习参考. 首先找到:/module/extend/admin/template/setting.tpl.php 找到: <td><?php echo timetodate(filemtime(DT_ROOT.'/sitemaps.xml'));?>   <a href="?moduleid=<?php echo $moduleid;?>&file

ECShop后台站点地图关于 Deprecated: Assigning the return value of new by reference is deprecated的错误的解决办法

今天对后台系统进行一些简单的操作,当点击  系统设置---站点地图  时发现提示: Deprecated: Assigning the return value of new by reference is deprecated 的错误,如下图: 起先以为是代码的问题,可是一想到这个模板是官网的默认模板,对sitemap.php文件进行查找后未能发现问题.后来将错误内容从网上一查找,原来是由于从php5.3开始后,废除了php中的"=&"符号,所以删除&符号即可. 删除

[.NET领域驱动设计实战系列]专题九:DDD案例:网上书店AOP和站点地图的实现

一.引言 在前面一专题介绍到,要让缓存生效还需要实现对AOP(面向切面编程)的支持.所以本专题将介绍了网上书店案例中AOP的实现.关于AOP的概念,大家可以参考文章:http://www.cnblogs.com/jin-yuan/p/3811077.html.这里我简单介绍下AOP:AOP可以理解为对方法进行截获,这样就可以在方法调用前或调用后插入需要的逻辑.例如可以在方法调用前,加入缓存查找逻辑等.这里缓存查找逻辑就在方法调用前被执行.通过对AOP的支持,每个方法就可以分为3部分了,方法调用前

站点地图静态生成功能

原来的站点地图,因为启用了伪静态,所以直接伪静态指向生成站点地图的PHP文件,HTML地图无所谓,是正常的,而XML地图,则一直不能显示.从代码里查看,是正常的,后来用http状态查询发现,xml的返回状态是 Content-Type: text/xml 而启用伪静态的sitemap.xml返回的状态还是根html的代码返回状态是一样的 Content-Type: text/html; charset=utf-8 尝试了很多办法解决,发现用PHP返回header值也还是不行,必须静态生成,需要在

Mvc中使用MvcSiteMapProvider实现站点地图之基础篇

MvcSiteMapProvider 是针对 ASP.NET MVC 中,提供菜单. 网站地图. 站点地图路径功能,以及更多的工具.它提供配置使用一个可插入的体系结构,可以是 XML. 数据库或动态生成导航结构的能力. 如图: 在MvcSiteMapProvider 中有三种方式来实现站点地图:XML,.NET Attributes,IDynamicNodeProvider. 下面,我们先通过XML方式来实现站点地图. 1.新建Mvc4项目,选择Internet应用程序.然后通过Nuget来安装

利用ASP.NET里自带的站点地图工具制作网站站点地图

站点地图很方便能快速给我们导航我们要去访问的地址,能按层级关系分门别类,给用户一个很好的用户体验,很好的看到自己当前所在的网站位置 站点地图,又称网站地图,它就是一个页面,上面放置了网站上所有页面的链接.大多数人在网站上找不到自己所需要的信息时,可能会将网站地图作为一种补救措施.搜索引擎蜘蛛非常喜欢网站地图. 网站地图是一个网站所有链接的容器.很多网站的连接层次比较深,蜘蛛很难抓取到,网站地图可以方便搜索引擎蜘蛛抓取网站页面,通过抓取网站页面,清晰了解网站的架构,网站地图一般存放在根目录下并命名