Sep 19

This is simple code to generate xml sitemap using php. This code generates xml sitemap depending on sql query and it can support unlimited url (no url limit). On SEO point of view, the sitemap can be updated very frequently which is very big plus for your site SEO.

Read more to Get the code for generating xml sitemap –>

<?php

function makesitemap($url)
{
$file= fopen($url, “w”);

include_once(“connect.php”); //database parameters

$query = “SELECT id,title FROM articles order by added_on desc”;

$xml_outputĀ  = “<?xml version=\”1.0\” encoding=\”UTF-8\”?>\n”;
$xml_outputĀ  .= “<urlset xmlns=\”http://www.google.com/schemas/sitemap/0.84\”>\n”;
$xml_output.=”<!– Latest dumps sitemap generator at www.dumpsquestions.com –>”;

while($row=mysql_fetch_array($result))
{
$xml_output .= “\t<url>\n”;

/* $row['text'] = str_replace(“&”, “&”, $row['title']);
$row['text'] = str_replace(“<”, “<”, $row['title']);
$row['text'] = str_replace(“>”, “&gt;”, $row['title']);
$row['text'] = str_replace(“\”", “&quot;”, $row['title']);*/

$xml_output .= “\t\t<loc>http://www.dumpsquestions.com/how_to/”.$row['title'].”_”.$row['id'] .”.html</loc>\n”;

$xml_output .= “\t\t<lastmod>”.date(‘Y’).”-”.date(‘m’).”-”.date(‘d’).”</lastmod>\n”;
$xml_output .= “\t\t<changefreq>weekly</changefreq>\n”;
$xml_output .= “\t\t<priority>0.8</priority>”;
$xml_output.=”\n”;

$xml_output .= “\t</url>\n”;
}

$xml_output .= “</urlset>”;

//echo $xml_output;

fwrite($file, $xml_output);

fclose($file);
}
makesitemap(“sitemap-article.xml”);

?>

No related posts.

10 Responses to “PHP code to generate XML Sitemap”

  1. Polprav Says:

    Hello from Russia!
    Can I quote a post in your blog with the link to you?

  2. Admin Says:

    Yes you can.

  3. Freebies Says:

    Nice. Thank you for sharing this with us. its always fun to read good blog like this, keep up the good work.

  4. MoCua.Com Says:

    thanks

  5. virtual administrative services Says:

    This is very wonderful so nice and beautiful information thanks for this post.

  6. living room decorating ideas Says:

    Its great to see that people are sharing quite profitable information with each other and now we can move our selves to a new era.

  7. T Shirt Printing Says:

    Thanks for sharing these useful information! Hope that you will continue doing nice article like this.

  8. swarovski iphone 4 case Says:

    I must show my affection for your generosity supporting individuals that really need assistance with this particular subject matter. Your very own dedication to passing the message up and down was really interesting and has frequently made others like me to arrive at their objectives. Your entire valuable publication means much a person like me and a whole lot more to my mates. Thanks a lot; from all of us.

  9. Houston Home Security Says:

    Your website have very interesting article. I got knowledge from here. Besides that, your blog is so popular among the searchers from search engines. It means yours website is very good.

  10. BMW Gt1 Dis sss Says:

    Great a posting. common problems is G. transform their individual views much as well repeatedly.
    http://www.obd2center.co.uk/909-bmw-gt1-dis-sss

Leave a Reply

Please copy the string BULv9P to the field below:



www.dumpsquestions.com © 2009