PDA

View Full Version : Javascript/PHP Parse error, T_STRING



tcoble
10-22-2009, 02:59 AM
Hello,

I am in the process of updating a site to php to reduce time needed to update. Everything seems to be working until I add javascript for an embedded flash file then I get "Parse error: syntax error, unexpected T_STRING, expecting ',' or ';'"

Is it possible to re-write this code to be PHP friendly?


<?
echo'

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>| Title |</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="FGA DF" />
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
<script type="text/javascript" src="js/swfobject.js"></script>
<link href="css/dropdown.css" media="all" rel="stylesheet" type="text/css" />
<link href="css/default.advanced.css" media="all" rel="stylesheet" type="text/css" />
</head>
<script type= "text/javascript">
Var params = {};
params.bgcolor = "#FFFFFF";
params.menu = "false";
params.scale = 'noScale';
params.wmode = "opaque";
params.allowScriptAccess = "always";

var attributes = {};
attributes.id = 'Component';
attributes.name = 'Component'

var cacheBuster = Date.parse(new Date());

var stageW = 550;
var stageH = 374;

var flashvars = {};

flashvars.componentWidth = 560;
flashvars.componentHeight = 374;

flashvars.pathToFiles = "banner/";

flashvars.xmlPath = "xml/banner.xml";

swfobject.embedSWF('preview.swf', 'Component', stageW, stageH, '9.0.45', 'js/expressinstall.swf', flashvars, params, attributes);

</script>
<body>
<div class="centered">
<table width="73%" border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#000000" summary="summary" valign="top">
<tr bgcolor="#000000">
<th colspan="3" scope="col"> <div align="right">
<a href="./" target="_parent"><img src="images/concept_banner.jpg" alt="" width="950" height="111" /></a>
<div align="center">
<ul class="dropdown dropdown-horizontal">
<li id="Home"><a href="./" target="_parent" class="dir">Home</a></li>
<li id="ACS"><a href="../." class="dir"> Community Services</a>
<ul>
<li><a href="../.">Information and Referral</a></li>
<li><a href="../.">Financial Readiness</a></li>
<li><a href="../."> Emergency Relief</a></li>
<li><a href="../.">Employment Assistance</a></li>
<li><a href="../.">Exceptional Family Member</a></li>
<li><a href="../.">Mobilization and Deployment Readiness</a></li>
<li><a href="../.">Relocation Readiness</a></li>
<li><a href="../.">Family Advocacy</a></li>
<li><a href="../.">Sexual Assault Response</a></li>
<li><a href="../."> Family Team Building</a></li>
<li><a href="../."> Family Action Plan</a></li>
<li><a href="../."> Volunteer Corps </a></li>
</ul>
</li>
<li id="CYS"><a href="../." class="dir">Child Youth &amp; School Services</a>
<ul>
<li><a href="../.">Central Registration</a></li>
<li><a href="../.">Child Development Center</a></li>
<li><a href="../.">Family Child Care</a></li>
<li><a href="../.">School Age Services</a></li>
<li><a href="../.">Youth Services</a></li>
<li><a href="../.">Youth Sports and Fitness</a></li>
<li><a href="../.">School Liaison</a></li>
<li><a href="../.">Skies Unlimited</a></li>
</ul>
</li>
<li id="Recreation"><a href="../." class="dir">Recreation</a>
<ul>
<li><a href="../.">Physical Fitness Center</a></li>
<li><a href="../.">Auto Skills Shop</a></li>
<li><a href="../.">Outdoor Recreation</a></li>
<li><a href="../.">Wood Craft Shop</a></li>
<li><a href="../.">Indoor Playground</a></li>
<li><a href="../.">BOSS Warrior Zone</a></li>
<li><a href="../.">Sideline Sports Bar</a></li>
</ul>
</li>
<li id="Lodging"><a href="../." class="dir">Lodging</a> </li>
<li id=""><a href="../." class="dir"> Information</a>
<ul>
<li><a href="../.">Events Calendar</a></li>
<li><a href="../.">Administration</a></li>
<li><a href="../.">Locations Map</a></li>
<li><a href="../.">Phone Numbers</a></li>
<li><a href="../.">NAF Employment</a></li>
</ul>
</li>
</ul>
</div></th>
</tr>
</table>
</body>
</html>
';
?>

thetestingsite
10-22-2009, 03:04 AM
You need to include the PHP code as well in order for us to successfully help you.

tcoble
10-22-2009, 03:27 AM
Here is the full code:


<?
echo'

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>| Title |</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="FGA DF" />
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
<script type="text/javascript" src="js/swfobject.js"></script>
<link href="css/dropdown.css" media="all" rel="stylesheet" type="text/css" />
<link href="css/default.advanced.css" media="all" rel="stylesheet" type="text/css" />
</head>
<script type= "text/javascript">
Var params = {};
params.bgcolor = "#FFFFFF";
params.menu = "false";
params.scale = 'noScale';
params.wmode = "opaque";
params.allowScriptAccess = "always";

var attributes = {};
attributes.id = 'Component';
attributes.name = 'Component'

var cacheBuster = Date.parse(new Date());

var stageW = 550;
var stageH = 374;

var flashvars = {};

flashvars.componentWidth = 560;
flashvars.componentHeight = 374;

flashvars.pathToFiles = "banner/";

flashvars.xmlPath = "xml/banner.xml";

swfobject.embedSWF('preview.swf', 'Component', stageW, stageH, '9.0.45', 'js/expressinstall.swf', flashvars, params, attributes);

</script>
<body>
<div class="centered">
<table width="73%" border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#000000" summary="summary" valign="top">
<tr bgcolor="#000000">
<th colspan="3" scope="col"> <div align="right">
<a href="./" target="_parent"><img src="images/concept_banner.jpg" alt="" width="950" height="111" /></a>
<div align="center">
<ul class="dropdown dropdown-horizontal">
<li id="Home"><a href="./" target="_parent" class="dir">Home</a></li>
<li id="ACS"><a href="../." class="dir"> Community Services</a>
<ul>
<li><a href="../.">Information and Referral</a></li>
<li><a href="../.">Financial Readiness</a></li>
<li><a href="../."> Emergency Relief</a></li>
<li><a href="../.">Employment Assistance</a></li>
<li><a href="../.">Exceptional Family Member</a></li>
<li><a href="../.">Mobilization and Deployment Readiness</a></li>
<li><a href="../.">Relocation Readiness</a></li>
<li><a href="../.">Family Advocacy</a></li>
<li><a href="../.">Sexual Assault Response</a></li>
<li><a href="../."> Family Team Building</a></li>
<li><a href="../."> Family Action Plan</a></li>
<li><a href="../."> Volunteer Corps </a></li>
</ul>
</li>
<li id="CYS"><a href="../." class="dir">Child Youth &amp; School Services</a>
<ul>
<li><a href="../.">Central Registration</a></li>
<li><a href="../.">Child Development Center</a></li>
<li><a href="../.">Family Child Care</a></li>
<li><a href="../.">School Age Services</a></li>
<li><a href="../.">Youth Services</a></li>
<li><a href="../.">Youth Sports and Fitness</a></li>
<li><a href="../.">School Liaison</a></li>
<li><a href="../.">Skies Unlimited</a></li>
</ul>
</li>
<li id="Recreation"><a href="../." class="dir">Recreation</a>
<ul>
<li><a href="../.">Physical Fitness Center</a></li>
<li><a href="../.">Auto Skills Shop</a></li>
<li><a href="../.">Outdoor Recreation</a></li>
<li><a href="../.">Wood Craft Shop</a></li>
<li><a href="../.">Indoor Playground</a></li>
<li><a href="../.">BOSS Warrior Zone</a></li>
<li><a href="../.">Sideline Sports Bar</a></li>
</ul>
</li>
<li id="Lodging"><a href="../." class="dir">Lodging</a> </li>
<li id=""><a href="../." class="dir"> Information</a>
<ul>
<li><a href="../.">Events Calendar</a></li>
<li><a href="../.">Administration</a></li>
<li><a href="../.">Locations Map</a></li>
<li><a href="../.">Phone Numbers</a></li>
<li><a href="../.">NAF Employment</a></li>
</ul>
</li>
</ul>
</div></th>
</tr>
</table>
</body>
</html>
';
?>

thetestingsite
10-22-2009, 03:35 AM
Being that you are using single quotes for the echo, you have to use double quotes or escape the sinle quotes in your javascript code.

Hope this helps.

djr33
10-22-2009, 04:54 AM
<?php
$var = 'test'test'; //error '
$var = 'test\'test'; //no error
?>

You must escape similar quotes:
If you are using ', you need to escape with \' for 's.
If you are using ", you need to escape with \" for "s.

There is an alternative way to echo large chunks of data, but that requires using a special format and it can be annoying to use.
More info here: http://www.php.net/manual/en/function.echo.php
(Look in the example block for <<<END .... END;.)


Also, if you have long chunks of text, you can do that by exiting PHP for direct text, but within an if:

<?php
if ($var == 1) { ?>
test test test test
test test test test
test .....
<?php }
//the text above is only output when the if returns true.
?>


So there are some ideas to work with. You could also try a more complex strategy, storing your layout and content somewhere else (database, text files) and including those into your php code to generate the site. That's a better idea if you are making a complex, large site, though it takes a lot of work to setup.

tcoble
10-22-2009, 05:09 AM
Thank you very much. I am trying it now. :)

Thanks for the edit djr33.

fobos
10-22-2009, 05:20 PM
Hello,
when it says "syntax error, unexpected T_STRING, expecting ',' or ';'"
it means that your missing a comma or semicolon. If you look close:


attributes.id = 'Component'; <-- Semicolon
attributes.name = 'Component' <-- No Semicolon. ADD ONE..


Hope this helped

JasonDFR
10-22-2009, 08:02 PM
tcoble,

Unless you have changed something in your code since your first post, you do not, and should not, need to use php to output what you have there.

What are you trying to achieve by using php to echo all that markup?