Home > Backend Development > PHP Tutorial > 这段php生成xml文件的代码找不出错误,可是就是总是提示错误

这段php生成xml文件的代码找不出错误,可是就是总是提示错误

WBOY
Release: 2016-06-20 12:36:42
Original
915 people have browsed it

//声明DOMDocument对象
$_doc=new DOMDocument('1.0','utf-8');
//使用XML标准化格式输出
$_doc->formatOutput=true;
//创建root主标签
$_root=$_doc->createElement('root');
//创建一个version标签
$_version=$_doc->createElement('version');
//给version标签赋值
$_versionTextNode=$_doc->createTextNode('version1');
//将值放入version标签里
$_version->appendChild($_versionTextNode);
//把version标签添加到root标签里
$_root->appendChild($_version);
//将root主标签添加到XML文件里
$_doc->appendChild($_root);
//生成XML文件
$_doc->save('text2.xml');


回复讨论(解决方案)

$_versionTextNode=$_doc->createTextNode('version1');

分号是中文的。。。  PHP抛出的错误那么明显

谢谢,晕晕晕,怪不得找不到

<?xml version="1.0" encoding="utf-8"?><root>  <version>version1</version></root>
Copy after login

//给version标签赋值
$_versionTextNode=$_doc->createTextNode('version1') ; 这个是全角符号,改成半角的就可以了

谢谢,晕晕晕,怪不得找不到

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