displaying line breaks?

P

paul814

I have a MYSQL DB that people enter data into through a multiline
textbox, and then i display the data on a search results page. Here
is how I display it:

while($row=mysql_fetch_object($rs)){

print "<div class=\"message\">";
print " <h3>" . $row->itdate . "</h3>";
print " <h5>" . $row->itname . "</h5>";
print " <h4>" . $row->itcomments ."</h4>";
print "############### END OF RECORD ###############";
print "</div>";

}

this however does not display line breaks, everything runs on, can I
do something so that line breaks are displayed and my data is
displayed just like it was entered?

thanks.
 
J

Jukka K. Korpela

Scripsit (e-mail address removed):
print " <h3>" . $row->itdate . "</h3>";
print " <h5>" . $row->itname . "</h5>";
print " <h4>" . $row->itcomments ."</h4>";

That's semantically all wrong, since those pieces of texts are not
headings. A heading is a heading for something; but you have no copy
text.

Moreover, the order h3, h5, h4 is screwed. How could you have a 5th
level heading immediately after a 3rd level heading?

Try learning the basics of HTML first, really.
print "############### END OF RECORD ###############";

We used such dividers in line printer output in the early 1970s.
this however does not display line breaks, everything runs on, can I
do something so that line breaks are displayed and my data is
displayed just like it was entered?

It belongs to the basics of HTML that a line break is equivalent to a
space (or, in some contexts, an empty string) and that you need markup
such as <br> to generate a line break. It also belongs to the basics of
HTML that you should not format the text in a fixed manner but let
browsers do the division into lines, as they do unless you prevent it.

Apparently you're trying to make some user input to be converted to
HTML. It's pointless to re-invent the wheel when there's existing
software for such purposes, for doing it right.
 
R

richard

Scripsit (e-mail address removed):


That's semantically all wrong, since those pieces of texts are not
headings. A heading is a heading for something; but you have no copy
text.

Moreover, the order h3, h5, h4 is screwed. How could you have a 5th
level heading immediately after a 3rd level heading?

The so called "order" of headers usage is a myth.
The tag is merely intended for displaying text in a certain fixed
style. So if one wanted to display <h1> then an <h5> right below or
above, it makes no difference.

If I want to display an <h5> then an <h1> purely for looks, that's my
business.
 
J

Jonathan N. Little

richard said:
The so called "order" of headers usage is a myth.
The tag is merely intended for displaying text in a certain fixed
style. So if one wanted to display <h1> then an <h5> right below or
above, it makes no difference.

If I want to display an <h5> then an <h1> purely for looks, that's my
business.

Please disregard, the previous post it is absolutely incorrect. H1-H5 do
have semantic meaning and refer to the level of headings within the
structure of a document. If you wish different size text then style it.

/* some classes for styling */
..date{ font-size: 1.5em; }
..name { font-size: 1.2em; }
..comments{ font-size: 1.0em; }

example:

<div class="date"><?php echo $row->itdate; ?></div>
 
R

richard

Please disregard, the previous post it is absolutely incorrect. H1-H5 do
have semantic meaning and refer to the level of headings within the
structure of a document. If you wish different size text then style it.

/* some classes for styling */
.date{ font-size: 1.5em; }
.name { font-size: 1.2em; }
.comments{ font-size: 1.0em; }

example:

<div class="date"><?php echo $row->itdate; ?></div>


Which is what the h tags were designed to do in the first place.
Act as a shortcut to styling. Which were in use well before CSS came
around. So if I can do the same thing in CSS then why have h tags at
all?
 
P

paul814

Ok though aside from the styling of this text though...is there
something I could add to this that would format text just as it was
entered in my text box?

SO IF WAS ENTERED:
this is a test, this is a test.
test

test2
IT WOULD DISPLAY:
this is a test, this is a test.
test

test2


so it would skip lines when the actual input skips lines?
thanks.
 
B

Beauregard T. Shagnasty

richard said:
Which is what the h tags were designed to do in the first place.

No they are not. They are, as Jonathan said, semantic headings, just
like those outlines you wrote for English class - if you ever went to
high school.

Outline:

A. My Main Title
1. Chapter one
a. Paragraph about ...
b. Another paragraph about ...
2. Chapter two
a. Another paragraph ...
i. Keep going with sublevels...
ii. Keep going with sublevels...
Act as a shortcut to styling. Which were in use well before CSS came
around. So if I can do the same thing in CSS then why have h tags at
all?

Of course you may style <hx> elements different than the browser
default, but this has absolutely nothing to do with their true semantic
meaning.

Please don't post false advice in the future.
 
B

Beauregard T. Shagnasty

In said:
Ok though aside from the styling of this text though...is there
something I could add to this that would format text just as it was
entered in my text box?

I answered that question in comp.lang.php
 
J

Jonathan N. Little

Ok though aside from the styling of this text though...is there
something I could add to this that would format text just as it was
entered in my text box?

SO IF WAS ENTERED:
this is a test, this is a test.
test

test2
IT WOULD DISPLAY:
this is a test, this is a test.
test

test2

One way is with the php function nl2br

http://us.php.net/manual/en/function.nl2br.php
PHP: nl2br - Manual
 
P

paul814

this does not seem to work without echoing like I am doing here:

print " <h4>" . $row->itcomments ."</h4>";

I need it to work with that.
 
I

Iván Sánchez Ortega

this does not seem to work without echoing like I am doing here:

print " <h4>" . $row->itcomments ."</h4>";

I need it to work with that.

echo " <h4>" . nl2br($row->itcomments) ."</h4>";
echo " <h4><pre>" . $row->itcomments ."<pre></h4>";
echo " <h4 style='white-space:pre'>" . $row->itcomments ."</h4>";

.... *sigh* ...

--
 
C

C A Upsdell

richard said:
Which is what the h tags were designed to do in the first place.
Act as a shortcut to styling. Which were in use well before CSS came
around. So if I can do the same thing in CSS then why have h tags at
all?

Utterly wrong. Header tags have semantic meaning. If you wanted
styling in the olden days, long, long ago, before CSS, you should have
used the FONT tag, not header tags.
 
A

Andy Dingley

Please disregard, the previous post it is absolutely incorrect. H1-H5 do
have semantic meaning and refer to the level of headings within the
structure of a document. If you wish different size text then style it.

Richard isn't _absolutely_ incorrect here (and twice a day he knows
what time it is).

I would even go so far as to say that he's right and Jukka is wrong.

To look at your point, "H1-H5 do have semantic meaning and refer to
the level of headings" is absolutely right and represents _all_ that
we can say about <h*> elements (although I don't knwo what <h6> has
done to offend people). This is as much as the W3C recommendation
states: Headings have "level" and "level" is equated with
"importance".

Note that this does _NOT_ imply "ordering". The ISO HTML standard
additionally imposes ordering, but that's an addition and extension to
the W3C recommendation, not IMHO a wise or welcome change, simply
because it is a change.

So as you cited "level" and Richard discussed "ordering", it is wrong
to apply the level definition to his comment on order. He's not
actually wrong here.

Imposing order on HTML headings could easily have been done by the
W3C, but it wasn't. They are therefore not ordered and it is wrong for
any comment on a "web page" to claim that they should be. If some
organisation wants to impose additional constraints on its own pages,
to require ordering, then they're welcome to do so. Their constraint
doesn't apply to my pages though.

Jukka's statement, "the order h3, h5, h4 is screwed." is wrong,
because he's exceeding the applicable scope of the extra constraint
he's applying. It's a useful constraint to apply, when you want it,
and he's more than welcome to do it on his pages. However this doesn't
rule out some other corner of the web where such an ordering is
meaningful and sensible - the W3C certainly didn't rule it out, so we
shouldn't either. No, I don't know why you'd want this, but I know
it's a good thing not to forbid such things simply because I can't
think of a use for them.


To restore balance to the universe, Richard then posted "<h1> purely
for looks" where he _is_ incorrect, thus conserving the necessary
level of stupidity in his postings.
 
H

Harlan Messinger

richard said:
The so called "order" of headers usage is a myth.
The tag is merely intended for displaying text in a certain fixed
style.

You are completely misinformed on this subject.
So if one wanted to display <h1> then an <h5> right below or
above, it makes no difference.

If I want to display an <h5> then an <h1> purely for looks, that's my
business.

It's also your business if you want to wear mismatched socks or shoes or
wear a bra outside of your shirt. That doesn't mean you should be
advising other people to do so or imply that it's the correct way to do
things.
 
H

Harlan Messinger

richard said:
Which is what the h tags were designed to do in the first place.

"In the first place" it wasn't even assumed that people would be reading
HTML documents on a platform that had proportional fonts or variable
font sizes. The purpose of most tags was to define the *structure* of
the document.
Act as a shortcut to styling. Which were in use well before CSS came
around. So if I can do the same thing in CSS then why have h tags at
all?

That's what people *did*, and it was a disaster. In particular, how can
you use different headings for "styling" (without the use of CSS) when
each browser is free to display each heading level however it wants to?
 
H

Harlan Messinger

Andy said:
Richard isn't _absolutely_ incorrect here (and twice a day he knows
what time it is).

I would even go so far as to say that he's right and Jukka is wrong.

To look at your point, "H1-H5 do have semantic meaning and refer to
the level of headings" is absolutely right and represents _all_ that
we can say about <h*> elements (although I don't knwo what <h6> has
done to offend people). This is as much as the W3C recommendation
states: Headings have "level" and "level" is equated with
"importance".

Note that this does _NOT_ imply "ordering".

It's at least understood by anyone who knows a priori what headings are,
what they're for, and what is meant by the concept of different heading
levels. Sensible people will presumably not mark up the structure of
their documents in illogical ways, as that would be self-defeating.
Imposing order on HTML headings could easily have been done by the
W3C, but it wasn't.

Maybe they thought it was obvious from what they did say. I'd thought so.
 
A

Andy Dingley

It's at least understood by anyone who knows a priori what headings are,

Of course it is, but only if we permit "a priori" information to have
an influence here. That's a very bad idea for protocol
specifications! Judge conformity based on what the recommendation
_actually_ says, not on what we'd like it to mean.
Sensible people will

....vary widely in their context-dependent interpretation of
"sensible".
presumably not mark up the structure of
their documents in illogical ways, as that would be self-defeating.

Of course they won't, but what's "logic" here? It's context-
sensitive, because the scope of application of web markup is hugely
broad.

It's really not that hard to define a list (maybe "towns and villages
in alphabetical order"), to equate "level" with "city/town/village"
and to place the community's name within an appropriate <h*> according
to this level. Now generate a HTML page that matches these
constraints:- <h*> ordering will be all over the place. Yet because we
interpret <h*> as no more than "level" or "importance", this is a
perfectly logical, valid and conformant web page. We should not rule
it out because "the ordering is wrong"

Maybe they thought it was obvious from what they did say. I'd thought so.

What they also said was, "Some people consider skipping heading levels
to be bad practice.", so they obviously considered it. However this is
merely in one of the informative notes (yes, _some_ people do consider
ordering to be a requirement), so it's not part of the recommendation.
Nor can I construe any interpretation onto the normative rec and the
informative note that requires or recommends that I should do the
same.

Enforcing ordering is a practice that some (Jukka) follow and others
(Richard) don't. The W3C rec doesn't require authors to do either, or
even to choose one and stick with it.
 
J

Jukka K. Korpela

Scripsit Andy Dingley:
What they also said was, "Some people consider skipping heading levels
to be bad practice.", so they obviously considered it.

Not really; they just expressed some older HTML principles poorly.
Nor can I construe any interpretation onto the normative rec and the
informative note that requires or recommends that I should do the
same.

Normative rec? It's a recommendation issued by an industry consortium,
so if you want to play the game of normativeness, check _the_
international _standard_ on HTML. It's an exercise in futility, but it's
the standard (despite my efforts to prevent that nonsense years ago).

What matters is common sense, structural design principles, and the
descriptions of heading element semantics. Any statement about
"importance" and vague statements about "some people" are best
forgotten.
Enforcing ordering is a practice that some (Jukka) follow and others
(Richard) don't.

Of course, but that doesn't say much. You should add that one of these
practices makes sense and the other one is clueless. It is left as an
exercise to figure out which is which. You are allowed to check past
postings by named persons to see whether they make sense in general.
 
C

C A Upsdell

Andy said:
Then of the two, I'd have to side with Richard. Requiring ordering on
<h*> is assuming too much about HTML and limiting it to too narrow a
scope.

But ignoring ordering is understanding too little about HTML and
weakening its scope.

Let us not forget, however, that the OP was using header tags to obtain
the styling he wanted, not to suggest any hierarchy, and *this* I think
is inarguably foolish.
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top