我喜欢一些关于如何将字符串变量作为xml名称的一部分传递的指导。 我m根据用户表单选择运行mysql查询。然后我为结果创建一个xml。我想传递一个变量作为xml的名称。这是可能的吗?如何传递字符串变量作为xml名称的一部分
这就是我的工作代码:
$query = "SELECT * FROM $table WHERE diam = '$d' AND nom = '$n' AND dim = '$di' AND type = '$t'";
$query_result=mysql_query($query);
$num_rows = mysql_num_rows($query_result);
if($num_rows == 0) {
echo "bummer!";
} else {
#Creates a new DOMDocument
$doc = new DOMDocument("1.0", "utf-8");
#formats correctly the xml document
$doc->formatOutput = true;
#Create Parent Node
$parent_node = $doc->createElement('marker');
$parent_node = $doc->appendChild($parent_node);
#Row manip
while($row = mysql_fetch_assoc($query_result)) {
#adds node for each row
$row_node = $doc->createElement($table);
#appends the new node to the root
$occ = $parent_node->appendChild($row_node);
#add a child node for each field
foreach($row as $fieldname => $fieldvalue) {
$child = $doc->createElement($fieldname);
$child = $occ->appendChild($child);
$value = $doc->createTextNode($fieldvalue);
$value = $child->appendChild($value);
}
}
#saves generated domDocument into a file.
#If echo'ed outputs filezise in bytes
$xml_string = $doc->save('xmlOutput.xml');
}
,而不是硬编码“xmlOutput”我想要显示,可以说在直径列名。
Emm ...你可以使用'$ d'变量...或者我不明白什么? '$ xml_string = $ doc-> save($ d);' –
'$ name_of_file ='somefile.xml'; $ doc->保存($ name_of_file)'? –