Solved

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

Posted on 2011-03-11
4
486 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
Comment Utility
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 108

Accepted Solution

by:
Ray Paseur earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now