Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

escapeHTML printing problems

Status
Not open for further replies.

sulfericacid

Programmer
Joined
Aug 15, 2001
Messages
244
Location
US
have a few questions for you perl guru's.

print $query->escapeHTML(
join '', (
map{
defined($form{$_}) ? qq(<meta name=&quot;$_&quot; content=&quot;$form{$_}&quot;><br>\n):''
} qw ( abstract author distributor copyright description
robots language distribution rating )
),'<meta name=&quot;generator&quot; content=&quot;SpyderTagV1.0!&quot;><br>\n'
);


When I use that snipplet it literally prints out <br> rather than creating a
line break (on browser). I had it working earlier where it lined breaked on
the browser but the <br> showed up in the email. Without using any other
modules or making this really complicated, how can I get a line break on
browser without the <br> printing to screen or in the email?

2nd question, how would I go about assigning that entire segment into a
single scalar?

Thanks!

sulfericacid
 
By escaping all the characters that could be HTML, < will get translated into &lt; by escapeHTML(). For every &quot;<br>&quot; try using &quot;\<br>&quot;. This may retain the <. Unfortunately I'm not on computer where I can test it, as I'm not familiar with escapeHTML().

It may be worth looking at encode_entities from HTML::Entities as that will allow you to specifically set which HTML entities you wish to encode.

E.g. encode_entities($a, &quot;\200-\377&quot;); would encode the string in $a, by replacing all the extended characters set entries from \200 to \377, any other characters are left alone.

For the second question the following:

print $query->escapeHTML( .... );

can also be written as:

my $html = $query->escapeHTML( .... );
print $html;
Barbie
Leader of Birmingham Perl Mongers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top