Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Feb 2007
    Posts
    219
    Thanks
    25
    Thanked 1 Time in 1 Post

    parse error, unexpected <

    Why am I getting a
    Parse error: syntax error, unexpected '<'
    on this line ? And how to alter it so that it will work ?

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

  • #2
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    You missed a closing ' character here:

    Code:
    echo "	<a href='".$row['Link2]."' ><img class='articleimage' src='".$row['Image]."' alt='".$row['Alt']."' /></a>";
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. –G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting

  • #3
    Regular Coder
    Join Date
    May 2011
    Posts
    242
    Thanks
    1
    Thanked 57 Times in 56 Posts
    You can add the missing quotes ($row['Link2'], $row['Image'], $row['Alt']) or use the following
    PHP Code:
    printf("<a href=\"%s\"><img class=\"articleimage\" src=\"%s\" alt=\"%s\" /></a>"$row['Link2'], $row['Image'], $row['Alt']); 

  • #4
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Actually, your quotes are the wrong way around anyway. " should be used for html tag attributes. Best to change it to the following:
    PHP Code:
    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.

  • #5
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    Quote Originally Posted by BluePanther View Post
    Actually, your quotes are the wrong way around anyway. " should be used for html tag attributes. Best to change it to the following:
    PHP Code:
    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.
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. –G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting

  • #6
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    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 .


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •