Class. sitemap. php

Source: Internet
Author: User
<? PHP
/***************************************
$ File Name: class. sitemap. php $
$ Description: $
$ Versions: 1.0 $
$ Last modification date: 2007/01/01 09:04:11 $
$ Author: psdshow (psdshow@yahoo.com.cn) $
$ This Is Not A freeware, use is subject to license terms (non-free software, authorization required by the user) $
****************************************/
Class sitemap {
VaR $ charset = "UTF-8 ";
VaR $ S = "";

Function sitemap ($ encoding = ''){

If (empty ($ encoding )){
$ Encoding = "UTF-8 ";
}

$ This-> s = "<? Xml version = \ "1.0 \" encoding = \ "$ encoding \"?> \ N ";
$ This-> s. = "<urlset xmlns = \" http://www.google.com/schemas/sitemap/0.84\ "> \ n ";
}

/*****************
* $ Loc the url symbol to be escaped
Symbol & amp;
Single quotation marks '& apos;
Double quotation marks "& quot;
Greater than> & gt;
Less than <;
* $ Lastmod modification time W3C Datetime can use YYYY-mm-dd
* $ Changefreq update frequency always hourly daily weekly monthly yearly never
* $ Priority importance between 0.1-1.0
*******************/
Function addurl ($ loc, $ lastmod = '', $ changefreq ='', $ priority = ''){

$ Loc = htmlentities ($ loc, ENT_QUOTES );
$ This-> s. = "\ t <url> \ n \ t <loc> $ loc </loc> \ n ";

If (! Empty ($ lastmod )){
$ This-> s. = "\ t <lastmod> $ lastmod </lastmod> \ n ";
}

If (! Empty ($ changefreq )){
$ This-> s. = "\ t <changefreq> $ changefreq </changefreq> \ n ";
}

If (! Empty ($ priority )){
$ This-> s. = "\ t <priority> $ priority </priority> \ n ";
}
$ This-> s. = "\ t </url> \ n ";
}
 
Function buildsitemap ($ filename = ""){
$ This-> s. = "\ t </urlset> \ n ";
If (empty ($ filename )){
Header ("Content-Type: text/xml ");
Echo $ this-> s;
} Else {
$ This-> save2file ($ filename );
}
}

Function save2file ($ filename ){
$ Fp = @ fopen ($ filename, "w +") or die (sprintf ("failed to create file 1%", $ filename ));
@ Fwrite ($ FP, $ this-> S );
@ Fclose ($ FP );
}
}
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.