Posted By

eszpee on 01/18/08


Tagged

utf8 encode encoding i18n


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

melling
markon89


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.