PDA

View Full Version : parse error, unexpected T_STRING


hobbitTech
12-20-2007, 08:38 AM
I type this php formatting echo "<p>";
$f[1] = "Justin";
$f[2] = "Lloyd";
$f[3] = "Alexa";
$f[4] = "Devron";
$age["Justin"] = 45;
$age["Lloyd"] = 32;
$age["Alexa"] = 26;
$age["Devron"] = 15;
print "My friends names are " . $f[1] . ", " . $f[2] . ", " . $f[3] . ", and " . $f[4];
print "<p>";
print "Alexa is " . $age["Alexa"] .
" years old";
echo "<p>";
print "<br>";
print "Dear pregnant cow";
print "<p>";
echo "we hope that you will accept our apologies for taking your calf and milking you.";
//for all you cows out there please dont shun us for this rad comment;
?>"<p>"
<?
$like = "I like About";
print $like;
$num = 12345;
print $num;
echo "<p>";
print "<br>";
$tag = "Thomas Abraham Gutierrez";
print $tag;
echo "<p>";
print "<br>";
$over65 = true;
$price = 1.00;
if ( $over65 )
{
$price = .90;
}
print "Your price is $" . $price;
print "<br>";
echo "<p>";
echo "I like php language.";
print "<p>";
$h[1] = "David's house";
$h[2] = "Michael's house";
print "$h[1]";
print " is worth";
$ty[1] = "27 dollars";
$ty[2] = " 85 dollars";
print "$ty[2]";
?>
<?
echo "<p>";
$t[9] = "timmy";
$t[8] = "dad";
$t[7] = "mom';
echo "hippos $t[9]";. But when I upload it it says Parse error: parse error, unexpected T_STRING in /:censored.php on line 63

dang
12-21-2007, 08:48 AM
You don't have 63 lines listed above, only 56 so it looks like something is still going on below.

For starters, you don't have the beginning PHP tag at the top before your first echo.

You have a strange "p" after the first close tag (after your comment //for all the cows...
You don't have close tags for your paragraph tags. You should have an opening tag: <p> and an end tag </p> encapsulating the text.

You are mixing print and echos. Is there a reason?

If I were you I'd do all your assignments first, then echo out your strings.
You should make your array names more readable, ie: $friends = array(); $house = array();

On the line $t[7] = "mom'; you have a double quote and then a single quote ending the assignment. This would definitely cause an error. You need to use the same type, so either use double quotes or single quotes.

$t[7] = "mom";
or
$t[7] = 'mom';

I would recommend not putting array output inside quotes. Example, you have:
print "$ty[2]";

I would do:
print $ty[2];

If it's mid string you can do:

print "this is output" . $ty[2];

your script should look like:

<?php

$f[1] = "Justin";
$f[2] = "Lloyd";
$f[3] = "Alexa";
$f[4] = "Devron";
$age["Justin"] = 45;
$age["Lloyd"] = 32;
$age["Alexa"] = 26;
$age["Devron"] = 15;
$num = 12345;
$like = "I like About";
$tag = "Thomas Abraham Gutierrez";
$over65 = true;
$price = 1.00;

$h[1] = "David's house";
$h[2] = "Michael's house";

$ty[1] = "27 dollars";
$ty[2] = " 85 dollars";

$t[9] = "timmy";
$t[8] = "dad";
$t[7] = "mom";

echo "<p>";

print "My friends names are " . $f[1] . ", " . $f[2] . ", " . $f[3] . ", and " . $f[4];
print "<p>";
print "Alexa is " . $age["Alexa"] .
" years old</p>";
echo "<p>";
print "<br>";
print "Dear pregnant cow";
print "<p>";
echo "we hope that you will accept our apologies for taking your calf and milking you.";
//for all you cows out there please dont shun us for this rad comment;


print $like;

print $num;
echo "<p>";
print "<br>";

print $tag;
echo "<p>";
print "<br>";

if ( $over65 )
{
$price = .90;
}
print "Your price is $" . $price;
print "<br>";
echo "<p>";
echo "I like php language.";
print "<p>";

print "$h[1]";
print " is worth";

print $ty[2];

echo "<p>";

echo "hippos" . $t[9];

?>

I take it you are trying to learn PHP? Do you want some references?

hobbitTech
12-21-2007, 10:00 AM
Never mind I figured it out

dang
12-21-2007, 10:02 AM
K. Again, if you want resources for learning PHP, let me know.