SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Addict
    Join Date
    Mar 2003
    Location
    Greenville, SC
    Posts
    388
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    parse error/using double and single quotes.

    hello.

    In validating my page for valid XHTML compliency I got the following:

    1. Line 145, column 12: an attribute value must be a literal unless it contains only name characters

      <p><a href=/z30.php#1>Back to main page</a></p>

      You have used a character that is not considered a "name character" in an attribute value. Which characters are considered "name characters" varies between the different document types, but a good rule of thumb is that unless the value contains only lower or upper case letters in the range a-z you must put quotation marks around the value. In fact, unless you have extreme file size requirements it is a very very good idea to always put quote marks around your attribute values. It is never wrong to do so, and very often it is absolutely necessary.




    the backend code looks like this
    PHP Code:
     $smiley "<img src=$pathtosmilies/$filename border=0>" 
    I changed it to:
    PHP Code:
     $smiley '<img src="$pathtosmilies/$filename border='0' alt=''">' 
    which resulted in a parse error. How do I use the quotes nested within' eachother without getting this error while making my code valid XHTML??

  2. #2
    SitePoint Wizard DougBTX's Avatar
    Join Date
    Nov 2001
    Location
    Bath, UK
    Posts
    2,498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jive
    I changed it to:
    PHP Code:
     $smiley '<img src="$pathtosmilies/$filename border='0' alt=''">' 
    which resulted in a parse error. How do I use the quotes nested within' eachother without getting this error while making my code valid XHTML??
    The final valid XHTML image tag you want will look something like this:

    Code:
    <img src="image/path.gif" alt="smile" />
    You don't need the border="0" bit, because you can just use this bit of CSS to do that for every image on your page:

    Code:
    img { border: 0; }
    So, back to your question.

    You can't put double quotes inside double quotes, or single quotes inside single quotes, without escaping them.

    So try escaping them, like this: " => \"

    Gives:

    PHP Code:
    "<img src=\"$path/$filename\" alt=\"$alt\" />" 
    Hope that does the trick,
    Douglas
    Hello World

  3. #3
    SitePoint Guru
    Join Date
    Jul 2004
    Location
    Raleigh, NC
    Posts
    783
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $smiley = '<img src="$pathtosmilies/$filename border='0' alt=''">'
    2 problems:
    1) the contents of single quotes are interpretted literally except escaped characters. so $filename will be interpretted as the dollar sign followed by the string 'filename' rather than as a variable
    2) everytime you use the same quote that you began with, php thinks you are ending the string and expects certain things
    if you want to put more with it you need to concocnate with dots: $var = 'foo=' . $foo;
    if you want to use those characters literally (as you do), they must be escaped:
    $var = 'border=\'0\'';
    $var = "border=\"0\"";
    sidenote: with single quotes, this is valid but generally considered bad practice

  4. #4
    Non-Member emstro's Avatar
    Join Date
    Jul 2003
    Location
    Florida
    Posts
    186
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes - they need a special characters that only programmers use, then we wouldn't have to escape characters any more.... well until you started writing tutorials on how to use the special characters... aw crap never mind.

  5. #5
    SitePoint Addict
    Join Date
    Mar 2003
    Location
    Greenville, SC
    Posts
    388
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm still getting a parse error:

    PHP Code:
      $smiley "<img src= \".$path/$filename.\" alt=\".$alt.\" />" 

  6. #6
    SitePoint Wizard DougBTX's Avatar
    Join Date
    Nov 2001
    Location
    Bath, UK
    Posts
    2,498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jive
    I'm still getting a parse error:

    PHP Code:
      $smiley "<img src= \".$path/$filename.\" alt=\".$alt.\" />" 
    Looks good from here - did you remember to put the ';' on the end?

    Douglas
    Hello World

  7. #7
    Dinah-Moe Humm mudshark's Avatar
    Join Date
    Dec 2003
    Posts
    1,072
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Errors in your concatenation me thinks:

    PHP Code:
    $smiley "<img src=\"" $path "/" $filename"\" alt=\"" $alt "\" />"

  8. #8
    SitePoint Wizard DougBTX's Avatar
    Join Date
    Nov 2001
    Location
    Bath, UK
    Posts
    2,498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mudshark
    Errors in your concatenation me thinks:

    PHP Code:
    $smiley "<img src=\"" $path "/" $filename"\" alt=\"" $alt "\" />"
    Ah, yes - didn't notice that he had changed it from the working sample I gave him a couple of posts up........

    Douglas
    Hello World


Bookmarks

Posting Permissions

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