package ReadEncoding; use strict; use Apache::Constants qw(:common); sub handler { my $r = shift; return DECLINED if $r->main() || $r->content_type ne 'text/html'; my $file = $r->filename(); open FILE, "<$file" or return DECLINED; my $enc; while () { /^\s*$/ and next; /^\s*<\?xml\s+ (?:version=(?:"[^"]*"|'[^']*')\s+)? encoding=(["'])\s*([^\s"']+)\s*\1/x and $enc = $2; last; } close FILE or return DECLINED; defined $enc or return DECLINED; $r->content_type("text/html; charset=$enc"); return OK; } 1; # $Id: ReadEncoding.pm 2770 2004-03-17 22:39:32Z lefevre $