Hi there, God bless you.

Is there a function inside the CGI module or someplace else that takes
care of formating text for output. Let's say we are reading a text
field from a database that may have strange simbols and/or html tags
that you do not want to be interpreted as html by the browser
receiving the CGI output, and also you don't want to send it with the
<pre> or <code> tags.

At first, I was thinking that the escape() function could do the work,
but it don't. Do I have to roll my own function to do the work (like
in the example below)? or is there a better way to do it?

Also, if I have to roll the function, which other simbols do I have to
care about?

-- example script start -- cut here
#!/usr/bin/perl -Tw

use strict;
use CGI;

# minicgiprb 
#     mini-CGI format for testing.

# control CGI vars
$CGI::DISABLE_UPLOADS = $CGI::DISABLE_UPLOADS = 1;
$CGI::POST_MAX = $CGI::POST_MAX = 2048;

my $q = CGI->new();

my $texto = "This text has some newlines
and <some> things that <browser> <will>
see like tags but that aren't.";

print $q->header, $q->start_html;
print $texto, $q->hr;
print $q->escape($texto), $q->hr;
print &correct_str($texto);
print $q->end_html;


# This sub returns the text.
sub correct_str {
    my $ret_val = shift;

    $ret_val =~ s/</&lt;/g;
    $ret_val =~ s/>/&gt;/g;
    $ret_val =~ s/\n/<br>\n/g;
    $ret_val;
}
-- example script end -- cut here

Thank's in advance for any help with this problem, see you.
Roberto Ruiz

--
LINUX: the FREE 32 bit OS for [3456]86 PC's available NOW!

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to