3dkiwi has asked for the wisdom of the Perl Monks concerning the following question:

Oh great and wise ones I wish to partake in your wisdom for a moment.

I am using the CGI.pm and generating the page title via the

print $q -> start_html(-title=> 'xXxXxX™'), -style=>{'src'=>"./style.css"} );

code.

My problem is the HTML Entity (for the TradeMark) does not render properly.

I have tried the HTML::Entities module to decode the string first but with no success.

The entity works OK in the title of a standard HTML page.

Many thanks for any pearls of wisdom in advance.

3d

Replies are listed 'Best First'.
Re: HTML Entities in CGI.pm Titles
by moritz (Cardinal) on Nov 12, 2007 at 08:41 UTC
    This snippet works for me:

    use strict; use warnings; use HTML::Entities qw(decode_entities); use CGI; use Encode; my $title = decode_entities('xXxXxX™'); my $cgi = new CGI; print $cgi->header(-charset => 'utf-8'), $cgi->start_html(encode("utf-8",$title));

    It prints out

    Content-Type: text/html; charset=utf-8 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-U +S"> <head> <title>xXxXxX™</title>

    Note that the following line is buggy, but I believe this is fixed in never CGI versions:

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

      Moritz

      Yep works for me too.

      Thanks for that. I was not doing enough encoding and decoding, but am now :-)

      Ta muchly

      3d