Solved

Strange characters.

Posted on 1997-04-16
10
396 Views
Last Modified: 2008-02-26
Hello!

I have a litle problem. I have a formmailscript and som of the mail that I got contains a lot of strange characters insted of the swedish å,ä,ö. Can some one tell me how to replace those characters into other, for examper ä to ae, ö to oe and å to aa? Or is it possibel to always get swedish characters when someone enter something in the form?
I

foreach $pair (@pairs)
{
   ($name, $value) = split(/=/, $pair);

   $value =~ tr/+/ /;
   $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
   $name =~ tr/+/ /;
   $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
         
   $FORM{$name} = $value;
}
0
Comment
Question by:pucko
10 Comments
 
LVL 1

Author Comment

by:pucko
Comment Utility
Edited text of question
0
 

Expert Comment

by:keegi
Comment Utility
Swedish (and all other national) characters can have
different encodings. In WWW, the encoding normally used is
ISO-8859-1 (it means ISO Latin-1).

Just check, what you get when you enter e.g. %C4. If you
get Ä (Ä) then the problem is in the characters that are entered.

Replacing some characters is very easy in perl.
Just use replacement:
  s/ä/ae/g;

0
 
LVL 1

Author Comment

by:pucko
Comment Utility
Can I change the encoding in anyway?
How do I check %C¤
0
 
LVL 1

Author Comment

by:pucko
Comment Utility
I've found out by my self how to do, but how can I remove this question? It seems that all I can do is to add a coment and Edit the question.
0
 
LVL 4

Expert Comment

by:mikem
Comment Utility
To remove a question, you need to accept an answer and award the points.

Mike
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Accepted Solution

by:
cmarquis earned 20 total points
Comment Utility
Using the substitution function (s///) is a very easy way to do this as suggested by keegi. Another way to try this is to use the translation operator (tr/// or y///) which is used the same way as in sed.

eg. s/PATTERN/REPLACEMENT/switches
   tr/SEARCHLIST/REPLACEMENTLIST/switches
0
 
LVL 1

Author Comment

by:pucko
Comment Utility
tr don't work because å, ä ,ö seems to be more than one char.But I have alredy solved the problem by my self. Thanks anyway!
0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
%tr = ('å'=>'aa','ä'=>'ae','ö'=>'oe');
s/([åäö])/$tr{$1}/g;


0
 

Expert Comment

by:Nikki_Dorens
Comment Utility
I have the same problem, because in Portuguese we use characters with uml, tilde, grave, acute, cedilla and circumflex.
Maybe translating all these characters to an HTML &whatever; or &decimal; would work. I could not find a way to make this translation, too. Some characters have more than one HTML notation, like these ones:
ä = ä = ä
å = å = å
From there on I am not sure if making an array with these character notations for translation would work...
0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
%tr = (
'ä' => 'ä',
'ä' => 'ä',
'å' => 'å',
'å' => 'å',
);
s/(&[#\w]+;)/$tr{$1}/g;

s/&#(\d*);/chr $1/eg; #for just the &# numbers
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Perl script not writing to .csv file 6 98
Using Perl to parse rows 7 85
Perl Frameworks 1 51
Perl script to delete older files 6 42
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now