[英]saving xml data via php and using $vairables
I have seen many questions on here regarding saving data to xml and I have managed to create a form that does so (thanks guys who asked and answered), there is only one minor blip 我在这里看到了许多有关将数据保存到xml的问题,并且我设法创建了一个这样做的表单(感谢那些问和答的人),只有一个小问题
Here is the code so you know what I mean 这是代码,所以您知道我的意思
<?php
function insertxml($Iname,$Iurl)
{
$doc = new DOMDocument;
//$doc->preserveWhiteSpace = false;
$doc->load("bookmark.xml");
// we want a nice output
//$doc->formatOutput = true;
$root = $doc->getElementsByTagName('bookmark')->item(0);
$title = $doc->createElement('url', $Iurl);
$domAttribute = $doc->createAttribute('name');
$domAttribute->value = ('$Iname');
$title->appendChild($domAttribute);
$newtitle = $root->appendChild($title);
echo 'Wrote: ' . $doc->save("bookmark.xml") . ' bytes'; // Wrote: 72 bytes
}
$Name = $_POST['name'];
$Url = $_POST['url'];
insertxml($Name,$Url);
?>
and the form looks like so: 表单看起来像这样:
<!DOCTYPE html>
<html>
<head>
<title> Xml Reader</title>
</head>
<body>
<form action="index.php" method="post">
Name: <input type="text" name="name"><br>
URL: <input type="text" name="url"><br>
<input type="submit">
</form>
</body>
</html>
the code works fine however when I put 'Test' in the name box and ' http://test.com ' in the url box it comes out like this: 该代码可以正常工作,但是当我在名称框中输入“ Test”并在URL框中输入“ http://test.com ”时,结果如下:
<url name="$Iname">http://test.com</url>
What i would like is 我想要的是
<url name="test">http://test.com</url>
<url name="(what ever name I put in the name box)">(what ever name I put in the url box)</url>
ultimatly what syntax should i put for the following?: 最后,我应该为以下内容使用哪种语法?:
$title = $doc->createElement('url', $Iurl);
remove the quotes from your variable 从变量中删除引号
('$Iname')
should be 应该
($Iname)
then remove the braces as they are not needed, too (there is nothing to group): 然后也删除不需要的括号(也没有要分组的内容):
($Iname)
should be 应该
$Iname
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.