Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在xml文件中存储html表单值_Php_Javascript_Html_Xml - Fatal编程技术网

Php 在xml文件中存储html表单值

Php 在xml文件中存储html表单值,php,javascript,html,xml,Php,Javascript,Html,Xml,我在'item_detail'(data.html)字段中输入了15个字符,但我只想在xml文件(item.xml)的'itemdetail'元素中存储10个字符,我该怎么做 data.html---- data.php文件----------- 您可以使用php 作为一个补充说明,您应该在发布之前对$\u POST数据进行清理 编辑 我已经整理好了变量名,正如您使用xml变量覆盖post变量一样 data.php <?php $post_id= $_POST["idd"]; $post

我在'item_detail'(data.html)字段中输入了15个字符,但我只想在xml文件(item.xml)的'itemdetail'元素中存储10个字符,我该怎么做

data.html----

data.php文件-----------

您可以使用php

作为一个补充说明,您应该在发布之前对$\u POST数据进行清理

编辑

我已经整理好了变量名,正如您使用xml变量覆盖post变量一样

data.php

 <?php
$post_id= $_POST["idd"];
$post_item_detail = substr($_POST["itd"], 0,10);

$xml = new DomDocument();
$xml->load("item.xml");

$xml->formatOutput = true;   

$items = $xml->documentElement;
$itemsLength = $items->getElementsByTagName('item');
for ($i = 0; $i < $itemsLength->length; $i++) {
$itm = $items->getElementsByTagName('item')->item($i);
$oldItem = $items->removeChild($itm);
}


$items = $xml->firstChild;     
$item = $xml->createElement('item');   
$items->appendChild($item); 
$id = $xml->createElement('id');
$itemdetail = $xml->createElement('itemdetail'); 
$item->appendChild( $id );
$id->nodeValue = $post_id;
$item->appendChild( $itemdetail );
$itemdetail->nodeValue = $post_item_detail;

$xml->save("item.xml");

?>
load(“item.xml”);
$xml->formatOutput=true;
$items=$xml->documentElement;
$itemsLength=$items->getElementsByTagName('item');
对于($i=0;$i<$itemsLength->length;$i++){
$itm=$items->getElementsByTagName('item')->item($i);
$oldItem=$items->removeChild($itm);
}
$items=$xml->firstChild;
$item=$xml->createElement('item');
$items->appendChild($item);
$id=$xml->createElement('id');
$itemdetail=$xml->createElement('itemdetail');
$item->appendChild($id);
$id->nodeValue=$post\u id;
$item->appendChild($itemdail);
$itemdail->nodeValue=$post\u item\u detail;
$xml->save(“item.xml”);
?>
item.xml

<?xml version="1.0" encoding="UTF-8"?>
<doc>

</doc>


要存储前十个字符还是最后十个字符?是否要比输入少保存五个字符?你能举例说明你想要达到的目标吗?顺便说一句,使用POST请求,在使用
encodeURIComponent
对字符串进行编码后,应将
%20
替换为
+
。我想将'item\u detail'的前10个字符输入xml的'itemdetail'元素file@thomas,我尝试使用ur代码,但它给出了一个错误'Parse error:syntax error,第2行data.php中出现意外“=”是的,它正在工作。感谢您的帮助。您还可以提供从“item.xml”文件中删除所有元素的代码吗?我添加了一个方法,可以删除标记为item.xml的所有节点。但我想从xml文件中删除所有元素,包括根元素
$id= $_POST["idd"];
$item_detail= $_POST["itd"];


            $xml = new DomDocument();
            $xml->load("item.xml");
            $xml->formatOutput = true;   
            $items = $xml->firstChild;     
            $item = $xml->createElement('item');   
            $items->appendChild($item); 
            $id = $xml->createElement('id');
            $itemdetail = $xml->createElement('itemdetail'); 
            $item->appendChild( $id );
            $id->nodeValue = $id;
            $item->appendChild( $itemdetail );
            $ItemDetail->nodeValue = $item_detail;


            $xml->save("item.xml");

           }
$item_detail= substr($_POST["itd"], 0,10);
 <?php
$post_id= $_POST["idd"];
$post_item_detail = substr($_POST["itd"], 0,10);

$xml = new DomDocument();
$xml->load("item.xml");

$xml->formatOutput = true;   

$items = $xml->documentElement;
$itemsLength = $items->getElementsByTagName('item');
for ($i = 0; $i < $itemsLength->length; $i++) {
$itm = $items->getElementsByTagName('item')->item($i);
$oldItem = $items->removeChild($itm);
}


$items = $xml->firstChild;     
$item = $xml->createElement('item');   
$items->appendChild($item); 
$id = $xml->createElement('id');
$itemdetail = $xml->createElement('itemdetail'); 
$item->appendChild( $id );
$id->nodeValue = $post_id;
$item->appendChild( $itemdetail );
$itemdetail->nodeValue = $post_item_detail;

$xml->save("item.xml");

?>
<?xml version="1.0" encoding="UTF-8"?>
<doc>

</doc>