网页调用中采用gb2312真是坑爹。
方法:
Centos安装,先安装perl包,直接 yun install perl*
全装一个都不漏。
/******************************************************/
#!/usr/bin/perl
use XML::Simple;
use Data::Dumper;
use LWP::Simple;
use Encode qw/encode decode/;
#use utf8;
#my $file = 'test.xml';
#my $reader = XML::Simple->new();
#my $xml = $reader->XMLin($file);
$xml = get('');
$xml =~ s/encoding='GB2312'//; //关键点,把gb2312去掉
my $reader = XML::Simple->new();
my $xml1 = $reader->XMLin($xml);
print Dumper($xml1);
/**********************************************************/
如果部分报错:
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "en_US.UTF-8"
解决方法:
echo "export LC_ALL=C" >> /root/.bashrc
source /root/.bashrc
xml.php
header("Content-Type: application/xml");
$filename = "test.xml";
$result = file_get_contents($filename);
echo $result;
?>
test.xml
阅读(2297) | 评论(0) | 转发(0) |