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

feed utf8 encoding i18n LWPSimple


Versions (?)


Get the character encoding of a feed


Published in: Perl 


  1. use LWP::Simple;
  2.  
  3. sub getfeedencoding {
  4. #takes: feed url
  5. #returns: feed encoding based on what it says about itself in the XML header
  6. #sample string: encoding="UTF-8"
  7. my $feedurl = shift;
  8. my $pagecontent = get($feedurl);
  9. $pagecontent =~ m{encoding="(.*?)"};
  10. return $1 or undef;
  11. }

Report this snippet 

You need to login to post a comment.