使用 PHP 表单中的数据更新 xml 命名空间
P粉445714413
P粉445714413 2023-09-05 10:34:27
0
2
384
<p>在下面的示例中,PHP 表单使用字段中输入的文本更新 XML。</p> <p>XML 文件 labela.xml:</p> <pre class="brush:php;toolbar:false;">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; &lt;inventors&gt; &lt;person&gt; &lt;name&gt;change1&lt;/name&gt; &lt;comment&gt;change2&lt;/comment&gt; &lt;/person&gt; &lt;/inventors&gt;</pre> <p>用于更改 XML 文件中的“change1”和“change2”的 PHP 表单</p> <pre class="brush:php;toolbar:false;">&lt;script src=&quot;https://code.jquery.com/jquery-latest.min.js&quot;&gt;&lt;/script&gt; &lt;?php $xml = new DOMDocument(&quot;1.0&quot;, &quot;utf-8&quot;); $xml-&gt;formatOutput = true; $xml-&gt;preserveWhiteSpace = false; $xml-&gt;load(&quot;labela.xml&quot;); //Get item Element $element = $xml-&gt;getElementsByTagName(&quot;person&quot;)-&gt;item(0); //Load child elements $name = $element-&gt;getElementsByTagName(&quot;name&quot;)-&gt;item(0); $comment = $element-&gt;getElementsByTagName(&quot;comment&quot;)-&gt;item(0); //Replace old elements with new $element-&gt;replaceChild($name, $name); $element-&gt;replaceChild($comment, $comment); ?&gt; &lt;?php if (isset($_POST[&quot;submit&quot;])) { $name-&gt;nodeValue = $_POST[&quot;namanya&quot;]; $comment-&gt;nodeValue = $_POST[&quot;commentnya&quot;]; htmlentities($xml-&gt;save(&quot;labela.xml&quot;)); } ?&gt; &lt;form method=&quot;POST&quot; action=''&gt; name &lt;input type=&quot;text-name&quot; value=&quot;&lt;?php echo $name-&gt;nodeValue; ?&gt;&quot; name=&quot;namanya&quot; /&gt; comment &lt;input type=&quot;text-comment&quot; value=&quot;&lt;?php echo $comment-&gt;nodeValue; ?&gt;&quot; name=&quot;commentnya&quot;/&gt; &lt;input name=&quot;submit&quot; type=&quot;submit&quot; /&gt; &lt;/form&gt;</pre> <p>如何使用 PHP 从下面的 XML 结构中提取并更新字符串change1 和change2?</p> <pre class="brush:php;toolbar:false;">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; &lt;pt:document xmlns:pt=&quot;http://schemas.brother.info/ptouch/2007/lbx/main&quot; xmlns:barcode=&quot;http://schemas.brother.info/ptouch/2007/lbx/barcode&quot; xmlns:style=&quot;http://schemas.brother.info/ptouch/2007/lbx/style&quot; xmlns:text=&quot;http://schemas.brother.info/ptouch/2007/lbx/text&quot;&gt; &lt;pt:body currentSheet=&quot;Folha 1&quot;&gt; &lt;style:sheet name=&quot;Folha 1&quot;&gt; &lt;pt:objects&gt; &lt;barcode:barcode&gt; &lt;barcode:qrcodeStyle model=&quot;2&quot; eccLevel=&quot;15%&quot; /&gt; &lt;pt:data&gt;change1&lt;/pt:data&gt; &lt;/barcode:barcode&gt; &lt;text:text&gt; &lt;text:textStyle vertical=&quot;false&quot; /&gt; &lt;pt:data&gt;change2&lt;/pt:data&gt; &lt;text:stringItem charLen=&quot;7&quot;&gt; &lt;text:ptFontInfo&gt; &lt;text:logFont name=&quot;Arial&quot; /&gt; &lt;/text:ptFontInfo&gt; &lt;/text:stringItem&gt; &lt;/text:text&gt; &lt;text:text&gt; &lt;text:textStyle vertical=&quot;false&quot; /&gt; &lt;pt:data&gt;change3&lt;/pt:data&gt; &lt;/text:text&gt; &lt;/pt:objects&gt; &lt;/style:sheet&gt; &lt;/pt:body&gt; &lt;/pt:document&gt;</pre> <p>提前感谢所有花时间提供帮助的人</p>
P粉445714413
P粉445714413

최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!