Solved

Strange characters.

Posted on 1997-04-16
10
414 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 1

Author Comment

by:pucko
ID: 1203795
Edited text of question
0
 

Expert Comment

by:keegi
ID: 1203796
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
ID: 1203797
Can I change the encoding in anyway?
How do I check %C¤
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:pucko
ID: 1203798
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
ID: 1203799
To remove a question, you need to accept an answer and award the points.

Mike
0
 
LVL 1

Accepted Solution

by:
cmarquis earned 20 total points
ID: 1203800
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
ID: 1203801
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
ID: 1203802
%tr = ('å'=>'aa','ä'=>'ae','ö'=>'oe');
s/([åäö])/$tr{$1}/g;


0
 

Expert Comment

by:Nikki_Dorens
ID: 2290026
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
ID: 2291668
%tr = (
'ä' => 'ä',
'ä' => 'ä',
'å' => 'å',
'å' => 'å',
);
s/(&[#\w]+;)/$tr{$1}/g;

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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…

730 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