我最近在帮一个朋友做一个很简单的php应用
就是将表单填写的内容保存到一个xml文件里,在另一个php文件中读取这个xml
现在的问题是:
当表单的填写内容包含中文的时候,保存到xml文档中的节点值为空(就是无法保存到xml)
我猜测是字符编码设置的问题,但是不知道怎么设置,懂php的兄弟帮帮忙,谢谢!详细功能如下:
四个页面:
fillinform.html----1
display.php--------2
data.xml-----------3
list.php-----------4填写好表单1后,将数据发送至页面2,并在2中对从1中传来的数据进行解析并存至xml文件3
最后在列表文件4中得以显示(如果大家觉得我表达的不清楚的话我一会再把代码贴上来)
谢谢了

解决方案 »

  1.   

    我自己什么编码都没有写
    不知道写在那里
    我以前没有摸过php
      

  2.   

    比如这个xml是:
    <root>
    <item>
    <nodename></nodename>
    </item>
    </root>读xml:
    $site_config = new DOMDocument();
    $site_pat = "http://localhost:81/";
    $site_config->load( $site_pat."data.xml" ); 
     $site_informations = $site_config->getElementsByTagName( "item" ); 
    foreach( $site_informations as $site_information ){ 
    $site_sitename = $site_information->getElementsByTagName( "nodename" )->item(0)->nodeValue; 
    }写入XML:
    $root=$doc->createElement("root");
    $doc->appendChild($root); $info = $doc->createElement( "item" ); 
    $sitename = $doc->createElement( "nodename" ); 
    $sitename->appendChild( 
    $doc->createTextNode( "节点信息" )
    );
    $info->appendChild( $sitename ); 
    $root->appendChild( $info ); 
    $doc->save("data.xml");