...

View Full Version : parse error, unexpected <



docock
09-14-2011, 01:33 PM
Why am I getting a
Parse error: syntax error, unexpected '<' on this line ? And how to alter it so that it will work ?



echo " <a href='".$row['Link2]."' ><img class='articleimage' src='".$row['Image]."' alt='".$row['Alt]."' /></a>";

Rowsdower!
09-14-2011, 01:40 PM
You missed a closing ' character here:


echo " <a href='".$row['Link2]."' ><img class='articleimage' src='".$row['Image]."' alt='".$row['Alt']."' /></a>";

gvre
09-14-2011, 01:42 PM
You can add the missing quotes ($row['Link2'], $row['Image'], $row['Alt']) or use the following

printf("<a href=\"%s\"><img class=\"articleimage\" src=\"%s\" alt=\"%s\" /></a>", $row['Link2'], $row['Image'], $row['Alt']);

BluePanther
09-14-2011, 07:53 PM
Actually, your quotes are the wrong way around anyway. " should be used for html tag attributes. Best to change it to the following:


echo '<a href="'.$row['Link2'].'"><img class="articleimage" src="'.$row['Image'].'" alt="'.$row['Alt'].'" /></a>';

' renders a string as plain text, whereas " tells php to render variables inside the string meaning it takes longer to process plain text like you were doing.

Rowsdower!
09-14-2011, 08:11 PM
Actually, your quotes are the wrong way around anyway. " should be used for html tag attributes. Best to change it to the following:


echo '<a href="'.$row['Link2'].'"><img class="articleimage" src="'.$row['Image'].'" alt="'.$row['Alt'].'" /></a>';

' renders a string as plain text, whereas " tells php to render variables inside the string meaning it takes longer to process plain text like you were doing.

From an HTML validation perspective, no. This is absolutely not a *requirement.* You can use single or double quotes and it is still perfectly valid HTML either way. The convention is to use double quotes, but it's still a matter of taste until W3C creates a standard that says otherwise and even then, it will only be mandatory in that particular standard.

HTML 4.01 (strict), XHTML 1.0 (strict), and HTML5 all allow single quotes for attributes.

I won't argue about the PHP aspect, but quatations in HTML can be whatever the developer chooses.

BluePanther
09-15-2011, 06:45 PM
That's interesting, I always thought it was a requirement, not a convention. Thanks for the info :).

The PHP is optional as well obviously, but makes sense for multiple reasons :).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum