Jump to content
xisto Community
Chesso

Need Help With Javascript In Php Urgently.

Recommended Posts

If you look at: http://forums.xisto.com/no_longer_exists/

 

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:

 

<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="https://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 >_>.

Edited by Chesso (see edit history)

Share this post


Link to post
Share on other sites

I just see the problem with your code, simple replace the ',' with a ';' like this:

len=urls_array.length;for ( var i=0;  i<len; ++i )
And also i suggest to complete your script tag.

Best regards,

Share this post


Link to post
Share on other sites

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:

	// Initial result value to begin with.	result = "<?xml version=1.0 encoding=UTF-8?>\n<urlset xmlns=https://www.google.com/schemas/sitemap/0.84&%2339;;

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.

Edited by Chesso (see edit history)

Share this post


Link to post
Share on other sites

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:

 

$result = '<'.'?xml version="1.0" encoding="UTF-8"?'.'>'."\n".'<urlset xmlns="https://www.google.com/schemas/sitemap/0.84/;;
Actually just noticed this inside Javascript so the correct way would be:

 

result = '<'+'?xml version="1.0" encoding="UTF-8"?'+'>'+"\n"+'<urlset xmlns="https://www.google.com/schemas/sitemap/0.84/;;
or

 

result = <?php echo '<'.'?xml version="1.0" encoding="UTF-8"?'.'>'."\n".'<urlset xmlns="https://www.google.com/schemas/sitemap/0.84/;; ?>
Cheers,

 

MC

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.