Jump to content

[SOLVED] Setup XML


nezbo

Recommended Posts

What is the easyest way to setup a XML site map...

 

I am new to XML and i am not to sure how to go about it...

 

I am looking at getting a php file to look at a of database and maybe the structure of the site and bring back a list of links for the XML, to put in to google sitemap.

 

my site is www.darwenmtbclub.co.uk that i want to site map, and the list of rides are in a database.

 

any ideas will be great, and code will be better :)

 

Cheers

 

I am not to sure if this is the correct forum that i have put it on, but as i want to have some php code that will do it automaticly for me i guesses PHP help wat teh base place :)

Link to comment
https://forums.phpfreaks.com/topic/117331-solved-setup-xml/
Share on other sites

This is the code i have so far...

 

$string1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"><url><loc>";
$string2 = "</loc><lastmod>" . date("Y-m-d", mktime()) . "</lastmod><changefreq>daily</changefreq><priority>0.8</priority></url></urlset>";
$siteMapArray = array();
$siteMapArray[0] = "http://" . $_SERVER['HTTP_HOST'] . "/";
$siteMapArray[1] = "http://" . $_SERVER['HTTP_HOST'] . "/rideList.php";
$siteMapArray[2] = "http://" . $_SERVER['HTTP_HOST'] . "/forum.php";
$siteMapArray[3] = "http://" . $_SERVER['HTTP_HOST'] . "/forumMes.php";
$numberOfBaseLinks = count($siteMapArray);
for($i = 0; $i < $numberOfBaseLinks; $i++)
{	
	$XMLstring = $XMLstring . $string1 . $siteMapArray[$i] . $string2;
}
echo "<div align='center'>XML Created</div>";

Link to comment
https://forums.phpfreaks.com/topic/117331-solved-setup-xml/#findComment-603573
Share on other sites

the code i have so far

 

I have got it saving a file but when i try and open a file it comes up with errors.

 

I know you have said i need to add theis before any output

header ("content-type: text/xml");

but i am not to sure what you mean. sorry...

How can add this half way through the code?

 

 

 

	$string1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"><url><loc>";
$string2 = "</loc><lastmod>" . date("Y-m-d", mktime()) . "</lastmod><changefreq>daily</changefreq><priority>0.8</priority></url></urlset>";
$siteMapArray = array();
$siteMapArray[0] = "http://" . $_SERVER['HTTP_HOST'] . "/";
$siteMapArray[1] = "http://" . $_SERVER['HTTP_HOST'] . "/rideList.php";
$siteMapArray[2] = "http://" . $_SERVER['HTTP_HOST'] . "/forum.php";
$siteMapArray[3] = "http://" . $_SERVER['HTTP_HOST'] . "/forumMes.php";
$numberOfBaseLinks = count($siteMapArray);
for($i = 0; $i < $numberOfBaseLinks; $i++)
{	
	$XMLstring = $XMLstring . $string1 . $siteMapArray[$i] . $string2;
}
$myFile = "sitemap.xml";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $XMLstring;
fwrite($fh, $stringData);
fclose($fh);

echo "<div align='center'>XML Sitemap Created</div>";

Link to comment
https://forums.phpfreaks.com/topic/117331-solved-setup-xml/#findComment-603588
Share on other sites

:) code sorted

 

 

 

	$string0 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">";
$string1 = "<url><loc>";
$string2 = "</loc><lastmod>" . date("Y-m-d", mktime()) . "</lastmod><changefreq>daily</changefreq><priority>0.8</priority></url>";
$string3 = "</urlset>";
$siteMapArray = array();
$siteMapArray[0] = "http://" . $_SERVER['HTTP_HOST'] . "/";
$siteMapArray[1] = "http://" . $_SERVER['HTTP_HOST'] . "/rideList.php";
$siteMapArray[2] = "http://" . $_SERVER['HTTP_HOST'] . "/forum.php";
$siteMapArray[3] = "http://" . $_SERVER['HTTP_HOST'] . "/forumMes.php";
$XMLstring = $string0;

$numberOfBaseLinks = count($siteMapArray);
for($i = 0; $i < $numberOfBaseLinks; $i++)
{	
	$XMLstring = $XMLstring . $string1 . $siteMapArray[$i] . $string2;
}
$XMLstring = $XMLstring . $string3;
$myFile = "sitemap.xml";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $XMLstring);
fclose($fh);

echo "<div align='center'>XML Sitemap Created</div>";

Link to comment
https://forums.phpfreaks.com/topic/117331-solved-setup-xml/#findComment-603601
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.