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

P

Paul Furman

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
 
J

J.O. Aho

Paul said:
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>
--------------
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).
 
C

cwdjrxyz

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

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.
 
A

Adrienne Boswell

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 %>
 
P

Paul Furman

cwdjrxyz said:

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.
 
P

Paul Furman

Adrienne said:
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.
 
P

Paul Furman

cwdjrxyz said:
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.
 
T

Toby A Inkster

Paul said:
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/
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top