We Recommend

Learning Perl Learning Perl
In this smooth, carefully paced course, a leading Perl trainer teaches you to program in the language that threatens to make C, sed, awk, and the Unix shell obsolete for many tasks. This book is the "official" guide for both formal (classroom) and informal learning. It is fully accessible to the novice programmer.


Posted By

eszpee on 01/18/08


Tagged

utf8 encode encoding i18n


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

melling


Convert a string to utf8


Published in: Perl 


  1. use Encode;
  2.  
  3. sub toutf8 {
  4. #takes: $from_encoding, $text
  5. #returns: $text in utf8
  6. my $encoding = shift;
  7. my $text = shift;
  8. if ($encoding =~ /utf\-?8/i) {
  9. return $text;
  10. }
  11. else {
  12. return Encode::encode("utf8", Encode::decode($encoding, $text));
  13. }
  14. }

Report this snippet 

You need to login to post a comment.