Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Strange characters.

Posted on 1997-04-16
10
Medium Priority
?
435 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
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 40 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 85

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 85

Expert Comment

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

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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Six Sigma Control Plans
Suggested Courses

581 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