Gossamer Forum
Quote Reply
Convert accents to html
Hi,

I've just dug up some code I used in a perl script I had written. Got the idea from an OReilly book.

The idea is to modify data that will be displayed in order for it to be HTML compliant and hence compatible with most browsers. Some seem to be able to display for example the word summer in French correctly when I type "été" others (older ones) seem to need it to be written été

This is the code I used in my perl script :

$description = &conversion_html ($description);

and this is the sub routine :

########################## Accents html conversion

conversion_html {local ($chaine) = @_;local (%signes_html, $chaine_html);

%caracteres_html =
(
'à', 'à',
'â', 'â',
'é', 'é',
'è', 'è',
'ê', 'ê',
'î', 'î',
'ô', 'ô',
'ù', 'ù',
'û', 'û',
'ç', 'ç',);

$chaine_html =
join ("", keys %caracteres_html);$chaine =~ s/([$chaine_html])/$caracteres_html{$1}/go;return ($chaine);

##########################

As you can see this would also work to provide the correct codes if modified for most european languages.

I was trying to create a sub for it so that I could let my editors simply type in with accents their reviews and then this would convert to html compliant code.

But this was written years ago and I'm not really sure what to do about creating a sub. I've tried and failed miserably with 500 errors each time. If anybody has any ideas I'm sure this could be useful to others aswell...

Thanks, John
Significant Media
Quote Reply
Re: [Jag] Convert accents to html In reply to
You may also use HTML::Entities for that task (you can encode any character):
http://www.perldoc.com/...b/HTML/Entities.html

As minimal solution you can use GT::CGI::html_escape, GT::CGI::html_unescape which encodes/decodes:
<, >, &, " charaters.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] Convert accents to html In reply to
Thanks, that looks really interesting. What would the subroutine need to look like if I were to use the HTML::Entities. At the moment I can't get my head around the construction of the subroutine to pick out something like the description or title and apply HTML::Entities to provide the ISO-8859/1 compliant format.

I read one of your previous posts warning about hacking in a creating problems and I'm worried I'll do harm trying to test it out Blush

Thanks for your post /response on the Directory Name plug-in as well missed that one and it sounds very useful Wink

Thanks, John
Significant Media
Quote Reply
Re: [Jag] Convert accents to html In reply to
You should read doc of HTML::Entities...

Anyway, an examle code:
Code:
use HTML::Entities;

# Encode
my $chars2encode = "áéóü\"&<>";
my $description = encode_entities($description, $chars2encode);

# Decode
my $description = decode_entities($description);

The module can also export the %char2entity and the %entity2char hashes which contain the mapping from all characters to the corresponding entities.


And I'm glad that you like DirName converter plugin idea. Try it out, it is very flexible.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [Jag] Convert accents to html In reply to
Quote:
I read one of your previous posts warning about hacking in a creating problems and I'm worried I'll do harm trying to test it out
Yes, I'm serious about this. I think hack is very-very rarely needed.
Usually a global or plugin can solve the problem.
And I think global is useful in this case, too.

Also there is a file, where custom codes are allowed to be placed. As LSQL v2.2.0 announcement says:
Quote:
An admin/Links/Custom.pm file has been added which may contain any special instructions or custom code needed for your installation. By default it is empty, and it will not be overwritten by future upgrades. The file is loaded after Links.pm starts loading, but generally before any other modules.
Unfortunately the only advantage I see of it is, that plugin developers can use this area to place common functions there.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...