<?php
header( "Content-Type:text/html;charset = gb2312" ) ;
$str = <<<XMLCONTENT
<?xml version = "1.0" encoding = "gb2312" ?>
<Computer name = "Computer">
<Program type = "Program">
<PHP type = "test">PHP Text</PHP>
</Program>
<Program type = "Nature">
<Nature name = "Nature World!" />
</Program>
</Computer>
XMLCONTENT;
$xml = simplexml_load_string( $str ) ;
$xml["name"] = iconv( "gb2312", "utf-8", "Modified Computer " ) ;
$xml -> Program -> PHP = iconv( "gb2312", "utf-8", "Modified PHP Text" ) ;
$modi = $xml -> asXML( ) ;
file_put_contents( "modi.xml", $modi ) ;
$str_modi = file_get_contents( "modi.xml" ) ;
echo $str_modi ;
?>
如上,其实是很简单的一个程序,$str_modi应该就是整个xml文件了,echo $str_modi显示的结果应该就是修改过的xml文件,实际上,IE显示的结果和我想的一样,就是修改过的xml文件,但是chrome显示结果只有一句:Modified PHP Text,这是咋回事?