Forum Moderators: coopster

Message Too Old, No Replies

parse error, unexpected T STRING

Parse error in php code.

         

Drunk N Japan

8:07 pm on Feb 16, 2007 (gmt 0)

10+ Year Member



I have been through the forums trying to find an answer to my problem but I have yet to find one. What I probably nee is an extra set of eyes to see what I am missing. This is code from a index spider for my site but when I run the index page I receive the following error.

Parse error: parse error, unexpected T_STRING in /bla/bla/bla/bla.com/bla_html/spider/admin/messages.php on line 116

The line surrounding and the error line are
114
function printQuitReport($command_line) {
115
if ($command_line == 0)

116
print"<script language="JavaScript"> var LSPT=""; LSPT += "?durl=" + escape(document.URL); LSPT += "&hostname=" + location.hostname; LSPT += "&url=" + location.pathname; LSPT += "&query=" + escape(location.search) + escape(location.hash); LSPT += "&referrer=" + escape(document.referrer); LSPT += "&browser=" + escape(navigator.appName); LSPT += "&version=" + escape(navigator.appVersion); LSPT += "&os=" + escape(navigator.platform); LSPT += "&xdomain=army.com"; LSPT += "&custid=army"; </script> <script Language="Javascript"> document.write('<img src=http://'+'content.example.com/images/pixel.gif'+LSPT+' height="1" width="1">'); </script> <noscript><img src="http://content.example.com/images/pixel?version=nonjava" height="1" width="1"> </noscript></body></html>";

117
flush();
118
}

I know that is a monstrously long line of code but I did not write it I just have to fix it. The </body></html> tags are opened earlier in the program. I appreciate any suggestions anyone can give me.

Thanks,

Drunk

[edited by: jatar_k at 8:14 pm (utc) on Feb. 16, 2007]
[edit reason] examplified [/edit]

jatar_k

8:17 pm on Feb 16, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld Drunk N Japan,

it is just a matter of mismatched quotes

looking at the first bit

print"<script language="JavaScript">...

the string to be printed needs to be enclosed in quotes, either single or double

your couble quotes start right after the print but then there is a matching set right after language= therefore all you feed to your print is

print"<script language="

and the next bit looks like a string to the parser. You need to escape double quotes inside your string, like so

print"<script language=\"JavaScript\">...

and carry this on for all double quotes within that massive string

reference
[php.net...]

whoisgregg

8:21 pm on Feb 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld [webmasterworld.com], Drunk N Japan!

All your double quotes will need to be escaped... or you could use heredoc [php.net] syntax to avoid that:

 print <<<___EOF
<script language="JavaScript"> var LSPT=""; LSPT += "?durl=" + escape(document.URL); LSPT += "&hostname=" + location.hostname; LSPT += "&url=" + location.pathname; LSPT += "&query=" + escape(location.search) + escape(location.hash); LSPT += "&referrer=" + escape(document.referrer); LSPT += "&browser=" + escape(navigator.appName); LSPT += "&version=" + escape(navigator.appVersion); LSPT += "&os=" + escape(navigator.platform); LSPT += "&xdomain=army.com"; LSPT += "&custid=army"; </script> <script Language="Javascript"> document.write('<img src=http://'+'content.example.com/images/pixel.gif'+LSPT+' height="1" width="1">'); </script> <noscript><img src="http://content.example.com/images/pixel?version=nonjava" height="1" width="1"> </noscript></body></html>
___EOF;

Added: And I type slow... ;)

Added: Watch out if you copy and paste, the WebmasterWorld software adds a space at the end of the <<<___EOF line that needs to be removed.

[edited by: whoisgregg at 8:26 pm (utc) on Feb. 16, 2007]

jatar_k

8:23 pm on Feb 16, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



hehe, and I was bored so I escaped it

print "<script language=\"JavaScript\"> var LSPT=\"\"; LSPT += \"?durl=\" + escape(document.URL); LSPT += \"&hostname=\" + location.hostname; LSPT += \"&url=\" + location.pathname; LSPT += \"&query=\" + escape(location.search) + escape(location.hash); LSPT += \"&referrer=\" + escape(document.referrer); LSPT += \"&browser=\" + escape(navigator.appName); LSPT += \"&version=\" + escape(navigator.appVersion); LSPT += \"&os=\" + escape(navigator.platform); LSPT += \"&xdomain=army.com\"; LSPT += \"&custid=army\"; </script> <script Language=\"Javascript\"> document.write('<img src=http://'+'content.example.com/images/pixel.gif'+LSPT+' height=\"1\" width=\"1\">'); </script> <noscript><img src=\"http://content.example.com/images/pixel?version=nonjava\" height=\"1\" width=\"1\"> </noscript></body></html>";

parsed for me though I don't know if it does what you want

Drunk N Japan

8:42 pm on Feb 16, 2007 (gmt 0)

10+ Year Member



Ladies and Gentlemen,

We have a winner. Thank you for your suggestions. Jatar_k The code that you escaped worked wonderfully. whoisgregg, thank you for the advice, I had seen something similar in another post but had not relized that it would be required throughout the whole line. I had thought that the error was coming towards the end of that monster. My site is now re indexing so that I can search it and find the newer more relevant articles. This is the most awesomest forum ever. You guys rock.

It's five O'clock somewhere,

Drunk

jatar_k

1:15 am on Feb 17, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



our pleasure Drunk N Japan

>> It's five O'clock somewhere

hehe, after that now so guess the time is right ;)