<title> in the body (I know it's wrong)

Discussion in 'HTML' started by Paul Furman, Jul 28, 2007.

  1. Paul Furman

    Paul Furman Guest

    I know it's wrong but it works: putting the <title> in the body of the
    document inside another <head> because I'm generating this with php &
    kind of boxed myself into not having access to the text I want till I
    get well into the body, for example:
    http://edgehill.net/gallery/photo-update/6-24-07/pg1pc1
    I noticed that duplicate titles have no effect.

    --------------
    Also, regarding length, the W3C folks say
    http://www.w3.org/Provider/Style/TITLE.html
    "Whilst there is no limit on the length of a title (as it may be
    automatically generated from other data), information providers are
    warned that it may be truncated if long."

    I have no problem with truncating, the alternative would be for me to
    truncate it myself. I'm gathering the titles from photo annotations
    which are sometimes a long paragraph of text like:
    http://edgehill.net/gallery/cameras/pg1pc3

    Mozilla strips this to a about 300 characters:
    1) Gitzo G1298 tripod with Linhoff LN9051 ball head 2) TC-14E AF-S
    teleconverter 3) TC-20EII AF-S teleconverter 4) Tokina 300mm f/2.8 MF
    (most of that is lens shade & teleconverters 5) MC-20 release 6) 105mm
    f/2.8 AF-S VR Micro 7) Nikon D200 8) 135mm f/2

    IE7 strips it to about 100 characters:
    1) Gitzo G1298 tripod with Linhoff LN9051 ball head 2) TC-14E AF-S
    teleconverter 3) TC-20EII AF

    --
    Paul Furman Photography
    http://edgehill.net
    Bay Natives Nursery
    http://www.baynatives.com
     
    Paul Furman, Jul 28, 2007
    #1
    1. Advertising

  2. Paul Furman

    J.O. Aho Guest

    Paul Furman wrote:
    > I know it's wrong but it works: putting the <title> in the body of the
    > document inside another <head> because I'm generating this with php &
    > kind of boxed myself into not having access to the text I want till I
    > get well into the body, for example:
    > http://edgehill.net/gallery/photo-update/6-24-07/pg1pc1
    > I noticed that duplicate titles have no effect.


    The effect depends on the browser, most browsers are made to correct the ill
    written code that many WYSIWYG generates and badly written scripts as in your
    case.

    You should not echo out everything as soon as you have generated or fetched
    the data, you can store things in variables and have the html generation last

    <?PHP
    //do here what you need to fetch your data
    //and store it into variables like
    $mysqli = new mysqli_connect('localhost','root','','database');
    $result=$mysqli->query('select title from table where page='{$_GET['page']}');
    list($title)=$result->fetch_array();
    ?>
    <html>
    <title><? $title ?></title>
    </head>
    <body>
    Something
    </body>
    </html>

    > --------------
    > Also, regarding length, the W3C folks say
    > http://www.w3.org/Provider/Style/TITLE.html
    > "Whilst there is no limit on the length of a title (as it may be
    > automatically generated from other data), information providers are
    > warned that it may be truncated if long."
    >
    > I have no problem with truncating, the alternative would be for me to
    > truncate it myself.


    It's the browser that may truncate the title if the text is long, how long the
    title may be depends on the browser and the size of the window (many browsers
    alters the window title to the title).


    --

    //Aho
     
    J.O. Aho, Jul 28, 2007
    #2
    1. Advertising

  3. Paul Furman

    cwdjrxyz Guest

    On Jul 28, 1:57 pm, Paul Furman <> wrote:
    > I know it's wrong but it works: putting the <title> in the body of the
    > document inside another <head> because I'm generating this with php &
    > kind of boxed myself into not having access to the text I want till I
    > get well into the body, for example:http://edgehill.net/gallery/photo-update/6-24-07/pg1pc1
    > I noticed that duplicate titles have no effect.
    >
    > --------------
    > Also, regarding length, the W3C folks sayhttp://www.w3.org/Provider/Style/TITLE.html
    > "Whilst there is no limit on the length of a title (as it may be
    > automatically generated from other data), information providers are
    > warned that it may be truncated if long."
    >
    > I have no problem with truncating, the alternative would be for me to
    > truncate it myself. I'm gathering the titles from photo annotations
    > which are sometimes a long paragraph of text like:http://edgehill.net/gallery/cameras/pg1pc3
    >
    > Mozilla strips this to a about 300 characters:
    > 1) Gitzo G1298 tripod with Linhoff LN9051 ball head 2) TC-14E AF-S
    > teleconverter 3) TC-20EII AF-S teleconverter 4) Tokina 300mm f/2.8 MF
    > (most of that is lens shade & teleconverters 5) MC-20 release 6) 105mm
    > f/2.8 AF-S VR Micro 7) Nikon D200 8) 135mm f/2
    >
    > IE7 strips it to about 100 characters:
    > 1) Gitzo G1298 tripod with Linhoff LN9051 ball head 2) TC-14E AF-S
    > teleconverter 3) TC-20EII AF
    >
    > --
    > Paul Furman Photographyhttp://edgehill.net
    > Bay Natives Nurseryhttp://www.baynatives.com


    The W3C shows many validation errors, but your page works on 5 common
    browsers I have to test. If you end your url with just pg1, pc1, or
    just a slash, you get 3 different pages, one being a photo of a bay
    area country view. Likewise, using the error <script language =
    javascript 1.2> instead of the now required <script ="text/
    javascript"> works, despite being an error. The same for several other
    errors. The point is that all or some browsers may work for certain
    errors. However, with the next version upgrade, the browser may not
    work with some errors that it did before. Then the webmaster may have
    to hack a way around the problem or correct errors to get a certain
    browser to work again. Of course some new browsers have bugs,
    especially IE ones, but these usually are detected fairly early and
    posts in groups such as this point out the problem and how to get
    around it.
     
    cwdjrxyz, Jul 28, 2007
    #3
  4. Gazing into my crystal ball I observed Paul Furman <>
    writing in news:ykMqi.29886$:

    > I know it's wrong but it works: putting the <title> in the body of the
    > document inside another <head> because I'm generating this with php &
    > kind of boxed myself into not having access to the text I want till I
    > get well into the body, for example:
    > http://edgehill.net/gallery/photo-update/6-24-07/pg1pc1
    >


    Better to put all your logic at the beginning of your script. Close
    connections as soon as possible. It's also easier for you, as a
    developer, to put that stuff at the top, easier to find and debug. I
    write mostly ASP, but the same is true for any language, eg:

    <% option explicit%>
    <!--#include file="connectionstring_inc.asp"-->
    <% 'declare variables
    'open recordsets, get info and put it into arrays
    'close recordsets
    %>
    <!--#include file="linkrel_inc.asp"-->
    <% 'above file includes the Doctype, html and head elements, stylesheet,
    favicon, title, and meta information
    %>
    </head>
    <body>
    ....
    <!--#include footer_inc.asp"-->
    <% 'above closes db connection, end body and html %>


    --
    Adrienne Boswell at Home
    Arbpen Web Site Design Services
    http://www.cavalcade-of-coding.info
    Please respond to the group so others can share
     
    Adrienne Boswell, Jul 29, 2007
    #4
  5. Paul Furman

    Paul Furman Guest

    cwdjrxyz wrote:

    > On Jul 28, 1:57 pm, Paul Furman <> wrote:
    >
    >>I know it's wrong but it works: putting the <title> in the body of the
    >>document inside another <head> because I'm generating this with php &
    >>kind of boxed myself into not having access to the text I want till I
    >>get well into the body, for example:

    http://edgehill.net/gallery/photo-update/6-24-07/pg1pc1
    >
    > The W3C shows many validation errors,


    Oh yeah, I'm sure. I haven't tried validating for quite a while, my bad,
    though some of those are intentional errors like this one designed for a
    specific effect.

    > If you end your url with just pg1, pc1, or
    > just a slash, you get 3 different pages, one being a photo of a bay
    > area country view.


    original:
    http://edgehill.net/gallery/cameras/pg1pc3

    These should all take you to the first pic on the page:
    http://edgehill.net/gallery/cameras/pg1 (page#)
    http://edgehill.net/gallery/cameras/
    http://edgehill.net/gallery/cameras

    This produces an error, it's not designed to work:
    http://edgehill.net/gallery/cameras/pc3 (pic# with no page)
    (I could fix it with some more php coding & save another 2 characters in
    the url but oh well, if someone gets creative they can't be too
    surprised to get an error)

    This is a weird way to show the wrong page of thumbnails:
    http://edgehill.net/gallery/cameras/pg2pc3
    (the displayed pic is on the previous page) LOL



    > The point is that all or some browsers may work for certain
    > errors. However, with the next version upgrade, the browser may not
    > work with some errors that it did before. Then the webmaster may have
    > to hack a way around the problem or correct errors to get a certain
    > browser to work again.


    Thanks, good point, that's why I asked. In an ideal world I can fix this
    as J.O. suggested by doing all my processing before writing the html in
    php but it's a huge nighmare of include files & lotsa work to fix at
    this point.

    --
    Paul Furman Photography
    http://edgehill.net
    Bay Natives Nursery
    http://www.baynatives.com
     
    Paul Furman, Jul 29, 2007
    #5
  6. Paul Furman

    Paul Furman Guest

    Adrienne Boswell wrote:

    > Gazing into my crystal ball I observed Paul Furman <>
    > writing in news:ykMqi.29886$:
    >
    >>I know it's wrong but it works: putting the <title> in the body of the
    >>document inside another <head> because I'm generating this with php &
    >>kind of boxed myself into not having access to the text I want till I
    >>get well into the body, for example:
    >>http://edgehill.net/gallery/photo-update/6-24-07/pg1pc1

    >
    > Better to put all your logic at the beginning of your script.


    Yes, that's my problem. I'm not sure it's easier to debug though, that
    approach puts the html miles away from the relevant code so it's far
    from easy (to me anyways). But yeah I did it wrong. I did do it right in
    some portions of the code.

    > Close connections as soon as possible.


    No databse in this site believe it or not, it's all just nested folders
    with content & little .txt files for annotations & shortcuts! I believe
    it is rather hard on the poor server.

    > It's also easier for you, as a
    > developer, to put that stuff at the top, easier to find and debug. I
    > write mostly ASP, but the same is true for any language, eg:
    >
    > <% option explicit%>
    > <!--#include file="connectionstring_inc.asp"-->
    > <% 'declare variables
    > 'open recordsets, get info and put it into arrays
    > 'close recordsets
    > %>
    > <!--#include file="linkrel_inc.asp"-->
    > <% 'above file includes the Doctype, html and head elements, stylesheet,
    > favicon, title, and meta information
    > %>
    > </head>
    > <body>
    > ...
    > <!--#include footer_inc.asp"-->
    > <% 'above closes db connection, end body and html %>
    >
    >



    --
    Paul Furman Photography
    http://edgehill.net
    Bay Natives Nursery
    http://www.baynatives.com
     
    Paul Furman, Jul 29, 2007
    #6
  7. Paul Furman

    Paul Furman Guest

    cwdjrxyz wrote:

    > If you end your url with ...just a slash, you get different..


    OK thanks, I did see that on another page though not these ones, more to
    look into thanks again.

    --
    Paul Furman Photography
    http://edgehill.net
    Bay Natives Nursery
    http://www.baynatives.com
     
    Paul Furman, Jul 29, 2007
    #7
  8. Paul Furman wrote:

    > I know it's wrong but it works: putting the <title> in the body of the
    > document inside another <head> because I'm generating this with php &
    > kind of boxed myself into not having access to the text I want till I
    > get well into the body


    <?php

    // I don't know the title yet, so I'll turn on output buffering and
    // then output an empty title.
    ob_start();
    print "<html>\n";
    print "<head>\n";
    print "<title></title>\n";
    print "</head>\n";

    // OK. Now I know what the title is, so switch off output buffering
    // and replace the empty title with the known title.
    $title = 'Lalala';
    print str_replace('<title></title>',
    "<title>$title</title>",
    ob_get_clean());

    ?>

    --
    Toby A Inkster BSc (Hons) ARCS
    [Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
    [OS: Linux 2.6.12-12mdksmp, up 39 days, 16:46.]

    demiblog 0.2.2 Released
    http://tobyinkster.co.uk/blog/2007/07/29/demiblog-0.2.2/
     
    Toby A Inkster, Jul 30, 2007
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas Klemt
    Replies:
    1
    Views:
    474
    Steve C. Orr, MCSD
    Aug 10, 2003
  2. Replies:
    0
    Views:
    550
  3. Replies:
    1
    Views:
    569
    David
    Apr 24, 2007
  4. soonic
    Replies:
    11
    Views:
    1,804
    soonic
    Jul 27, 2011
  5. Andries

    I know, I know, I don't know

    Andries, Apr 23, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    254
    Gregory Toomey
    Apr 23, 2004
Loading...

Share This Page