Results 1 to 5 of 5

Thread: display correctly in view source

  1. #1
    Join Date
    Nov 2005
    Location
    Austin TX,US
    Posts
    71
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default display correctly in view source

    I created a template page which will be included in every page of the site.
    Code:
    <?php 
    echo '<html>';
    echo '<head>';
    echo '<title>'.$title.'</title>';..............
    ?>
    My question is when I view source of the individual pages - everything is displayed in a long string like this:
    Code:
    <html><head><title>.....</title>...................................
    How to make it displayed normally with line breaks - just the code in view source, not the actual content.
    <html>
    <head>
    <title>...

    I looks easy but I don't know. Thanks.

  2. #2
    Join Date
    Apr 2006
    Posts
    429
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    PHP Code:
    <?php
    echo '<html>' "\n";
    ?>
    Please don't mind me. I am just posting a lot of nonsense.

  3. #3
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    Quote Originally Posted by jr_yeo View Post
    PHP Code:
    <?php
    echo '<html>' "\n";
    ?>

    \n = inserts a newline "<br />"
    \t = inserts a tab
    \r = inserts a carriage return

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

    Default

    When echoing chunks of HTML, though, it's easier to break out of PHP parsing mode:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html/strict.dtd">
    <html>
      <head>
        <title><?php print $title; ?></title>
      </head>
      <body>
    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!

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Or, you can actually include that type of character in the PHP code:
    PHP Code:
    <?php
    echo "This has a
    line break"
    ;

    //or

    echo <<<EOF
    This text now can be formatted
    however you want
    include any symbols.. whatever
    and variables like 
    {$var}.
    Just end like:
    EOF;

    ?>
    The right method to use depends on the circumstances. Twey's idea of breaking out of the PHP makes a lot of sense sometimes, too.
    You can expand on that too:
    PHP Code:
    <?php
    if (1==1) { ?>
    This is just some html that will
    only be output if the IF statement returns true
    <?php
    }
    //now the PHP can continue
    ?>
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

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
  •