Gossamer Forum
Home : General : Perl Programming :

Line feeds/<BR>in DBMan SQL

Quote Reply
Line feeds/<BR>in DBMan SQL
Hi all,
I do know that this kind of question has been thrashed about in the Links SQL dev, plug-in and global forum some-time back.. but since it hasn't solved my issue and because Paul seems to be giving a lot of very useful answers in this forum, here goes:

I have a field name <%Content%>. Importing data into my db, it gets filled with lots of plain text - not HTML! This plain text contains invisible line feeds (hex 0B) and displays properly with paragraphs in all my editors.

I have a global name Content_Formatted :

sub {
my $tags = shift;
my $content = $tags->{Content};
$content = GT::CGI::html_escape ($content);
$content =~ s/\n/<BR>\n/g;
return $content;
}

In my template, I display <%Content_Formatted%> instead of <%Content%>. Now I should get all my plain texts displaying properly, ie line feeds converted to <BR>. That's what people have been saying. But no. Yet the global works because (?) if I insert a new line online modifying manually a record, the new line does display...

So something I've done is wrong or not working! I'd really appreciate some well-explained-for-layman-type-wisdom !
Thanks in advance
Charly
Quote Reply
Re: [charly] Line feeds/<BR>in DBMan SQL In reply to
=~ s/\r// might help?
------------------
Dorg Hurgler Van Schongleur,
NordHein Van Resetelem, Belgium.
Eck SchekeBuugler Technologies.
Quote Reply
Re: [VanSchongluer] Line feeds/<BR>in DBMan SQL In reply to
Thanks Dorg for the suggestion. I had already tried:

$content =~ s/\r/<BR>\n/g;

with no change (text still not formatted)

and I tried your (but not sure about your complete line and expecting error):

$content =~ s/\r//<BR>\n/g;

which generates:

Unable to compile 'Content_Formatted'. Reason: syntax error at (eval 14) line 5, near "BR>"

So now? Anybody else got suggestions?

Charly

Last edited by:

charly: Jun 15, 2002, 11:56 PM
Quote Reply
Re: [charly] Line feeds/<BR>in DBMan SQL In reply to
Ok a couple of things to try....I'm not sure which will work if any.

Number one...

Try changing:

$content =~ s/\n/<BR>\n/g;

to

$content =~ s/\n/<BR>\n/sg;

If that doesn't work you could try:

$content =~ s/\r?\n?/<BR>\n/sg;

Then if that doesn't work try:

$content =~ s/\015\012/<BR>\n/sg;

I got out of bed 5 minutes ago so it they don't work please don't hate me Cool
Quote Reply
Re: [Paul] Line feeds/<BR>in DBMan SQL In reply to
Thanks Paul!
Here are results of each of your suggestions:

$content =~ s/\n/<BR>\n/sg;
result : no difference, no formatting
====
$content =~ s/\r?\n?/<BR>\n/sg;
result: the whole text becomes a single one-letter column !!
ie.

T
h
e

b
i
g

c
a
t

s
m
i
l
e
s
.....etc
===
$content =~ s/\015\012/<BR>\n/sg;
result : no difference, no formatting

So it's got to be something else ?????
Cheers
Charly
Quote Reply
Re: [charly] Line feeds/<BR>in DBMan SQL In reply to
Hi again,

I found this on www.cgiscript.net:

[$variable] =~ s/([^\w\s])/''.ord($1).';'/ge;
(Accompagning text says "Use this code to convert non-word characters to the html format. This is useful for displaying forms populated with variables that have odd characters or for 'escaping' variables prior to saving them to a database.")

so (ever hopefull..) in my global I replace
$content =~ s/\n/<BR>\n/g;
with:
$content =~ s/([^\w\s])/''.ord($1).';'/ge;
result:

The sky44; on a summer night44; is a wonder to behold44; a spectacle that leads one to dream of distant worlds58; the Moon44; the planets44; the thousands of stars and galaxies which one can more or less easily identify46; The tranquillity of this celestial heaven is sometimes disturbed by a shooting star44; the twinkling lights of an airplane44; or the silent passing of a satellite46;11;11;It is not infrequent44; however44; that one is surprised by something strange44; and initially unrecognisable46; But before one39;s imagination takes hold and prompts one to think of extra45;terrestrials44; it would be better to first tell the French space agency46;11;11;CNES is one of the rare international organisations interested in accounts of curious phenomena in the atmosphere46; Since 197744; the space agency has been helping civilian and military authorities understand the precise nature of Un45;identified Aerospace Phenomena 40;PAN41;46;11;11;The unit involved is the Rare Aerospace Phenomena Study Department 40;SEPRA41; based at the CNES technical centre in Toulouse46; Since 197744; the department has developed a precise analytical methodology and today has accumulated a considerable database46;11;11;38;quot59;We are involved in the framework of well defined procedures (etc.etc...)

Gee. This is real Sherlock Holmes stuff! This gives me (us?) clues because this addition to the global shows us where each new paragraph starts, ie. at the points where there is ;11;11;
Other deductions: 44; is a comma
58; is a colon
46; is a period etc...

Does this help you perl substitution experts ?
Charly

Last edited by:

charly: Jun 16, 2002, 10:22 AM
Quote Reply
Re: [charly] Line feeds/<BR>in DBMan SQL In reply to
Would you be able to email me a copy of your file so I can try a few ideas?

If so my email is pwilson@wiredon.net

I'm determined not to let this beat me/us.
Post deleted by Paul In reply to

Last edited by:

Paul: Jun 16, 2002, 11:23 AM