|
|
|
|
![]() ![]() |
Sep 2 2006, 03:22 AM
Post
#1
|
|
|
Teh Coder Group: Members Posts: 1,053 Joined: 18-April 06 From: Australia Member No.: 12,833 myCENTs:89.25 |
If you look at: http://www.chessoscorner.com/tools/google_...p_generator.php
You can see it produces an error like this: Parse error: syntax error, unexpected T_STRING in /home/chesso/public_html/tools/google_sitemap_generator.php on line 65 This particular section is not PHP code. The php TAG has been ended before my javascript code and reopened after my javascript code........ This page however works perfectly using WAMP5 locally on my pc (may have something to do with it using a newer version of PHP). Here is the javascript code in question: CODE <script language="javascript"> function generate_sitemap() { // Setup our variables. var last_mod = document.getElementById("last_mod").value; var change_freq = document.getElementById("change_freq").value; var priority = document.getElementById("priority").value; var urls = document.getElementById("urls").value; var result = ""; // Split up the urls into an array. var urls_array = urls.split("\n"); // Initial result value to begin with. result = '<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">'; // Loop through urls. Maybe add url validation later. for ( var i=0, len=urls_array.length; i<len; ++i ) { result = result + "\n <url>"; result = result + "\n <loc>" + urls_array[i] + "</loc>"; result = result + "\n <lastmod>" + last_mod + "</lastmod"; result = result + "\n <changefreq>" + change_freq + "</changefreq>"; result = result + "\n <priority>" + priority + "</priority>"; result = result + "\n </url>"; } // Now add the final code to the result. result = result + "\n</urlset>"; // Now put the end result in the sitemap box for users to copy. document.getElementById("sitemap").value = result; } </script> Anyone see a problem with this? It's just to generate a basic Google Sitemap, something built out of boredom based on my own sitemap.xml file meh >_>. This post has been edited by Chesso: Sep 2 2006, 03:25 AM |
|
|
|
Sep 2 2006, 04:11 AM
Post
#2
|
|
|
Super Member Group: [HOSTED] Posts: 805 Joined: 8-April 06 From: Lima - Peru Member No.: 12,579 myCENTs:46.87 |
I just see the problem with your code, simple replace the ',' with a ';' like this:
CODE len=urls_array.length; for ( var i=0; i<len; ++i ) And also i suggest to complete your script tag. Best regards, |
|
|
|
Sep 2 2006, 04:29 AM
Post
#3
|
|
|
Teh Coder Group: Members Posts: 1,053 Joined: 18-April 06 From: Australia Member No.: 12,833 myCENTs:89.25 |
I just have the same error.
The other pages that have javascript are basically 100% the same besides the obvious specifics and they work fine uploaded to asta host and locally. This one only seems to work locally. It appears to be a problem with me setting result = "<?xml blah blah", it doesn't like the code in it. Which should be void because it's outside of the php tags and is inside quotes. Iv'e even tried a few different ways of quoting it (single out, double in, double out, single in etc). EDIT: It loads fine without this: CODE // Initial result value to begin with. result = "<?xml version=1.0 encoding=UTF-8?>\n<urlset xmlns=http://www.google.com/schemas/sitemap/0.84'>"; Obviously there should be double quotes for the atributes inside that string, I tried single quoting outside and double quotings inside and others but still get the error. This post has been edited by Chesso: Sep 2 2006, 04:32 AM |
|
|
|
Sep 2 2006, 07:00 AM
Post
#4
|
|
|
PESTICIDAL MANIAC Group: Members Posts: 626 Joined: 1-September 04 From: Auckland, New Zealand Member No.: 27 |
The problem is short tags <?xml..., which is why I think servers should have it turned off, and people should use the proper <?php.
To overcome it you would need to do this: CODE $result = '<'.'?xml version="1.0" encoding="UTF-8"?'.'>'."\n".'<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">'; Actually just noticed this inside Javascript so the correct way would be: CODE result = '<'+'?xml version="1.0" encoding="UTF-8"?'+'>'+"\n"+'<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">'; or CODE result = <?php echo '<'.'?xml version="1.0" encoding="UTF-8"?'.'>'."\n".'<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">'; ?> Cheers, MC |
|
|
|
Sep 2 2006, 07:02 AM
Post
#5
|
|
|
Teh Coder Group: Members Posts: 1,053 Joined: 18-April 06 From: Australia Member No.: 12,833 myCENTs:89.25 |
Yep that's what I ended up doing.
I also always use <?php and ?>, I have seen many problems because of only using <?, I guess short tags must have been turned off. I think it is turned off by default on my local setup. |
|
|
|
![]() ![]() |
Similar Topics
| Topics | Topics | |
|---|---|---|
|
|
|
|
Lo-Fi Version | Time is now: 5th December 2008 - 01:33 AM |