Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: ' and this "

  1. #1
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default ' and this "

    I can't figure out how can to use this ' and " within one long string?

    This is the part of the string that's causing the problem.

    Code:
    <li><a href="../rewind/">Where We've Been</a></li>
    Actually & #39 ; worked (spaces are added to show it). Don't know there's another way though?
    Last edited by bluewalrus; 01-11-2009 at 07:14 PM. Reason: fixed grammar 4 times

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Try:
    Code:
    <li><a href="../rewind/">Where We\'ve Been</a></li>
    If your using single quotes, and:
    Code:
    <li><a href=\"../rewind/\">Where We've Been</a></li>
    If your using double.
    Jeremy | jfein.net

  3. The Following User Says Thank You to Nile For This Useful Post:

    bluewalrus (01-11-2009)

  4. #3
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    OO okay thanks

  5. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Glad to help.
    When your using single quotes, slash(' \ ') before single quotes.
    " same same " double quotes, "same same ...." double quotes.
    Jeremy | jfein.net

  6. The Following User Says Thank You to Nile For This Useful Post:

    bluewalrus (01-11-2009)

  7. #5
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    OO now I really get it hah. So I don't need to use the single quote (') when the text is containing the (") I can just stop its reading of it (escaping?) with the /" and keep it all with in a double quote. So now I have a new question when should I use the single quotes?

  8. #6
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    You can use single quotes anytime you like.
    I would not use single quotes when including variables(unless needed), for example:
    Code:
    echo "Hello ".$var."!";
    Is more characters then:
    Code:
    echo "Hello {$var}";
    ({ and } not needed...)
    Jeremy | jfein.net

  9. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    If you need to do this for HTML, chances are you should be breaking out of PHP parsing mode instead.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #8
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Or you could do something like this Twey:
    PHP Code:
    echo <<< HTML
    <p>"Hello, it's a wonderful day!" says Nile...</p>
    HTML; 
    Jeremy | jfein.net

  11. #9
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    What do you mean by breaking out of PHP parsing? I'm altering html with the php then echoing the final result.

  12. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Heredocs are also an option, but they screw up the formatting of the code (since you can't have whitespace before the end token), as well as being very slow. An output buffer would actually be more efficient.

    bluewalrus: instead of:
    Code:
    <?php
      echo '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head><title>';
      echo get_title_text();
      echo '</title></head><body><p>'
      echo get_body_text();
      echo '</p></body></html>';
    ?>
    ... or something silly like that, write:
    Code:
    <?php
      $title = get_title_text();
      $body = get_body_text();
    ?>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
      <head>
        <title>
          <?php echo $title; ?>
        </title>
      </head>
      <body>
        <p>
          <?php echo $body; ?>
        </p>
      </body>
    </html>
    It has four added benefits:
    1. readability, since you can format the code nicely for output rather than worrying about what the containing PHP looks like;
    2. efficiency, since the whole thing doesn't have to be parsed as PHP;
    3. simplicity, as it doesn't require you to follow escaping rules for strings; and
    4. clear distinction between code and output, which provides three benefits of its own:
      1. allows you to store the output template in a different place (e.g. in a different file);
      2. allows you to completely change what's to be output at any point in the code; and
      3. allows you to start a session without worrying about whether the flow of code has caused output to happen at some point previously.
      See also Smarty, which provides a mechanism and assorted tools for further separation of code and content.
    Last edited by Twey; 01-11-2009 at 11:06 PM. Reason: Fix Smarty link
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •