Solved

php error in javascript ( PHP Parse error:  syntax error, unexpected T_STRING )

Posted on 2011-03-11
4
496 Views
Last Modified: 2012-05-11
I have copied the exact source code of this site because I would like to use this example:
http://www.geocodezip.com/v3_GoogleEx_directions-draggable2Xml.html

I can't find out why I'm getting this error within this javascript:

PHP Parse error:  syntax error, unexpected T_STRING in /var/www/html/domain/test4.html on line 202

Why does my server try to execute javascript as php in this case starting at line 202? There is no

<?php ...

?>

in this javascript.  Really strange ..



0
Comment
Question by:seopti
  • 2
4 Comments
 

Author Comment

by:seopti
ID: 35110881
I found out it is because of this line in .htaccess:

Addhandler application/x-httpd-php .html .php

Seems I have to change it.
0
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 250 total points
ID: 35110965
Interesting... That line in .htaccess says, Take all URLs with file names that end in .html or .php and feed them to the PHP parser.  I use that quite often when I have a colleague developer writing in Dreamweaver.  There may be something else wrong, however.  You might need to turn off the "short open tag" settings if you have any XML in the mix.
0
 

Author Comment

by:seopti
ID: 35111053
Thanks but when using:
php_flag short_open_tag off


all my other php scripts will not be parsed.
0
 
LVL 82

Assisted Solution

by:hielo
hielo earned 250 total points
ID: 35111210
I agree with Ray. This line:

document.getElementById("polyline").value="<?xml version='1.0' encoding='UTF-8'?>\n<markers>\n";

is "seen/interpreted" as:
document.getElementById("polyline").value="<?phpxml version='1.0' encoding='UTF-8'?>\n<markers>\n";

because you do have short_tag_open set to true. So it will attempt to execute xml..., but that is NOT valid php syntax. If you cannot set it off, what you need to do is enclose the <?xml...?> in single quotes :

document.getElementById("polyline").value="<?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>\n<markers>\n";

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question