Home > Backend Development > PHP Tutorial > PHP操作XML有关问题

PHP操作XML有关问题

WBOY
Release: 2016-06-13 13:37:02
Original
803 people have browsed it

PHP操作XML问题
我用php生成xml如下

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
$xml = '<?xml version="1.0" encoding="utf-8"?>'."\r\n";
$xml .= '<user>'."\r\n";
$xml .= "\t".'<person_siteurl>'.www.163.com.'</person_siteurl>'."\r\n";
foreach (array(1,2,3) as $value){
   $xml .= "\t".'<job_keys>'.$value.'</job_keys>'."\r\n";
}
$xml .= '</user>'."\r\n";
$sxe = new SimpleXMLElement($xml);
$sxe->asXML(APPPATH.'user.xml');

Copy after login


生成了user.xml文件,我现在要想添加一个:
李四
该怎么添加啊,前面跟"\t" ,后面跟"\r\n" ? 

感谢~~

------解决方案--------------------
PHP code
$sxe = new SimpleXMLElement($xml);
$sxe->addChild('username', '李四');
$sxe->asXML(APPPATH.'user.xml'); <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template