Convert a string to utf8


/ Published in: Perl
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.