Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Google Forum


You are currently viewing our The Google Forum as a guest. Please register to participate.
Login



Reply
php to xml for sitemaps
Old 08-09-2005, 05:32 PM php to xml for sitemaps
NuWeb.co.uk's Avatar
NuWeb.co.uk is OFFLINE

Posts: 361
Trades: 0
Here is an example of a xml, googls infact. This needed for google sitemaps.
Code:
<?xml version="1.0" encoding="UTF-8" ?> 
- <urlset xmlns="http://www.google.com/schemas/sitemap/0.84">
- <url>
  <loc>http://www.google.com/BUILD</loc> 
  <lastmod>2005-04-30T03:45:08+00:00</lastmod> 
  </url>
- <url>
  <loc>http://www.google.com/about.html</loc> 
  <lastmod>2005-05-07T00:45:09+00:00</lastmod> 
  </url>
- <url>
  <loc>http://www.google.com/addurl.html</loc> 
  <lastmod>2005-03-11T23:45:16+00:00</lastmod> 
  </url>
  </urlset>
So what im wanting to do, is that my domain for every item on my website is:
http://www.nuweb.co.uk/index.php?action=play&id=X
X is a number.

In one row in mysql i have all the numbers in that will replace X ..
What i was wondering is, is their a way to "GENERATE" a XML like the one above, for every ID i have in my mysql table?
NuWeb.co.uk is offline
Reply With Quote
View Public Profile Visit NuWeb.co.uk's homepage!
 
 
Register now for full access!
Old 08-09-2005, 10:07 PM
zilla's Avatar
Experienced Talker

Posts: 39
Trades: 0
Well u can make an XML file like that with PHP and mySQL. Since you have the database just make an script that will create the XML like any normal PHP script just put content type text/xml in the headers.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
zilla is offline
Reply With Quote
View Public Profile Visit zilla's homepage!
 
Old 08-10-2005, 10:42 AM Run This Script
MightyMaster's Avatar
Ultra Talker

Posts: 401
Location: Appleton, WI
Trades: 0
Create a PHP File and enter the following coding:

Code:
<?

// list the directories you do not want to include
// in the sitemap. Relative to the browser path
// for example, if you are on the domain www.yourdomain.com
// and you do not want to list any files in www.yourdomain.com/images/
// then enter /images in the array below

$ignoreArray = array ('/errorlog', '/uploaded_images', '/n', '/stats', '/images', '/cgi-bin');
$ignoreExtensions = array ('.gif', '.jpg', '.js');





// no need to change anything below
$sitemap = new RJGoogleSiteMap(".", $ignoreArray, $ignoreExtensions);

class RJGoogleSiteMap {

	// this is the initializing function
	// defaults to current directory

	// some variables for general use
	var $browserPath;
	var $primaryFolder;
	var $ignoreArray;
	var $ignoreExtensions;

	function RJGoogleSiteMap($folder = ".", $ignoreArray = "", $ignoreExtensions = "") {

		$this->primaryFolder = $folder;
		$this->ignoreArray = $ignoreArray;
		$this->ignoreExtensions = $ignoreExtensions;

		// set the browser path
		$this->getBrowserPath();

		// generate the header
		echo $this->createXMLHeader();

		// start processing the specified folder
		$folders[] = $folder;

		while ($current_folder = array_pop($folders)) {

			$folder = opendir($current_folder);

			// open directory and start reading all files
			while ($file = readdir($folder)) {

				// skip if this is the current directory or, the parent
				if ($file == "." || $file == "..") {
					continue;
				}

				$filename = $current_folder.DIRECTORY_SEPARATOR.$file;

				// check for ignore lists
				$flag = 0;
				$toremove = "";

				$tmpfile = $this->getURL($filename);

				if(is_array($this->ignoreArray))
				{
					$this->tmpArray = array();

					foreach ($this->ignoreArray as $item) {
						if ($tmpfile == $this->browserPath.$item)
						{
							$flag = 1;
						}
						else
							array_push($this->tmpArray, $item);
					}

					$this->ignoreArray = $this->tmpArray;
				}

				if(is_array($this->ignoreExtensions))
				{
					foreach($this->ignoreExtensions as $item)
					{
						$length = strlen($item) * -1;

						if(strtolower(substr($filename, $length)) == strtolower($item))
						{
							$flag = 1;
							break;
						}
					}
				}

				// check if the current file is a directory or not
				if ($flag == 0) {
					if (is_dir($filename)) {
						// add to array for further processing
						array_push($folders, $filename);
						continue;
					} else
						$this->makeXML($filename);
				}
			}

			closedir($folder);
		}

		// generate the footer
		echo $this->createXMLFooter();
	}

	function makeXML($file) {

		// now we do the actual processing here
		// and generate the xml for this file

		// generate last modification date/time
		$file_info = stat($file);
		$lastmod = $file_info[9];
		$lastmod = date('Y-m-d\TH:i:s', $lastmod);

		// get the time difference
		$timediff = date('O', $lastmod);
		$timediff = substr($timediff, 0, 3) . ":" . substr($timediff, 3, 2);
		$lastmod .= $timediff;

		$file = $this->getURL($file);

		$str = "<url>";
		$str .= "<loc>".$file."</loc>";
		$str .= "<lastmod>2005-7-21</lastmod>";
		$str .= "<priority>1</priority>";
		$str .= "<changefreq>weekly</changefreq>";
		$str .= "</url>";
		echo $str;
	}

	function getBrowserPath() {
		$scriptlocation = split('/', $_SERVER["REQUEST_URI"]);
		array_pop($scriptlocation);
		$this->browserPath = join('/', $scriptlocation);
		$this->browserPath = "http://".$_SERVER["HTTP_HOST"].$this->browserPath;
	}

	function createXMLHeader() {

		header("Content-type: text/xml");
		$str = '<?xml version="1.0" encoding="UTF-8"?>';
		$str .= '<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">';
		return $str;
	}

	function getURL($filename) {

		// now make sure the primary folder is removed from the path
		// and ensure this is done just once

		$pos = strpos($filename, $this->primaryFolder);
		if (!($pos === false))
			$filename = substr_replace($filename, "", $pos, strlen($this->primaryFolder));

		return $this->browserPath.$filename;
	}
	function createXMLFooter() {
		return "</urlset>";
	}
}
?>
Then run the page ..... It will create an XML file of your php files. I use this on my site.
MightyMaster is offline
Reply With Quote
View Public Profile
 
Old 08-10-2005, 12:59 PM
OmuCuSucu's Avatar
Vi Veri Veniversum Vivus

Posts: 1,168
Name: Dragos-Valentin
Location: Cluj-Napoca, RO
Trades: 0
MightyMaster, i have a news.php that i use like this:

news.php?id=1; news.php?id=2 ... will your script work for that?

i think the script you have there is for STATIC websites not DYNAMIC ones.

am i wrong?
__________________
.
» Please remember to add to my Talkupation if you enjoyed my post. Thank you :)
.
OmuCuSucu is offline
Reply With Quote
View Public Profile
 
Old 08-10-2005, 02:52 PM
MightyMaster's Avatar
Ultra Talker

Posts: 401
Location: Appleton, WI
Trades: 0
Honestly I don't know if it will work on dynamic sites .... I use it on my static sites though. It doesn't hurt to try it. All you have to do is copy it to a file and run it. See what it spits out at ya.
MightyMaster is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to php to xml for sitemaps
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.23018 seconds with 12 queries