我正在尝试使用php domdocument将数据插入到xml中。然而,当我按Enter键时,它只显示一个空白页面,显示没有错误。我做错了什么?
更新:
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
$xmldoc = new DOMDocument();
if(file_exists('test.xml')){
$xmldoc->load('test.xml');
} else {
$xmldoc->loadXML('<root/>');
}
/*get the values of the html: */
$title_ar = $_POST["title_ar"];
$title_en = $_POST["title_en"];
$intro = $_POST["intro"];
$v_ar = $_POST["v_ar"];
$v_en = $_POST["v_en"];
$v_tren = $_POST["v_tren"];
/*get the values of the html: */
$root = $xmldoc->firstChild;
if ($xmldoc->getElementsByTagName("title")->length == 0) {
/* Arabic */
$el_title_ar = $xmldoc->createElement('title');
$root->appendChild($el_title_ar);
$text_title_ar = $xmldoc->createTextNode($title_ar);
$el_title_ar->appendChild($text_title_ar);
/* Arabic */
/* English */
$el_title_en = $xmldoc->createElement('title');
$root->appendChild($el_title_en);
$text_title_en = $xmldoc->createTextNode($title_en);
$el_title_en->appendChild($text_title_en);
/* English */
}
else if ($xmldoc->getElementsByTagName("introduction")->length == 0) {
$el_intro = $xmldoc->createElement('introduction');
$root->appendChild($el_intro);
$el_intro_para = $xmldoc->createElement('para');
$el_intro->appendChild($el_intro_para);
$text_intro = $xmldoc->createTextNode($intro);
$el_intro_para->appendChild($text_intro);
}
$verse = $xmldoc->createElement('verse');
$root->appendChild($verse);
/* Arabic */
$verse_p = $xmldoc->createElement('p');
$verse->appendChild($verse_p);
$v_ar_p = $xmldoc->createTextNode($v_ar);
$verse_p->appendChild($v_ar_p);
/* Arabic */
/* English Translation*/
$verse_trans = $xmldoc->createElement('trla');
$verse->appendChild($verse_trans);
$v_en_trans = $xmldoc->createTextNode($v_en);
$verse_trans->appendChild($v_en_trans);
/* English Translation*/
/* English Transliteration*/*/
$verse_translit = $xmldoc->createElement('trli');
$verse->appendChild($verse_translit);
$v_en_translit = $xmldoc->createTextNode($v_tren);
$verse_translit->appendChild($v_en_translit);
/* English Transliteration*/
/*Save the XML File*/
$xml->formatOutput = true;
$xmldoc->save('test.xml');
header("Location: index.php");
?>
答案 0 :(得分:3)
$title-ar
是非法的变量名称。这将意味着'变量$title
减去常量ar
,这将使它成为表达式,并且您不能将(=
)任何内容分配给表达式。在开发时你最好打开display_errors
,它会告诉你有关解析错误的信息。