防止PHP删除XML标记
我希望XML用户以HTML形式输入,就像在PHP中输入所有元素/标记一样,我尝试了PHP的简单XML,但它从XML中删除了所有标记,并向我显示这些XML标记中的内容/值,例如:防止PHP删除XML标记,php,html,xml,Php,Html,Xml,我希望XML用户以HTML形式输入,就像在PHP中输入所有元素/标记一样,我尝试了PHP的简单XML,但它从XML中删除了所有标记,并向我显示这些XML标记中的内容/值,例如: Hello 用户以HTML形式输入这个,我只得到Hello,但我需要完整的代码 编辑: 另一个示例XML代码: <Orders> <Order> <email>myemail@gmail.com</email> <Products> <Pr
Hello
用户以HTML形式输入这个,我只得到Hello,但我需要完整的代码
编辑:
另一个示例XML代码:
<Orders>
<Order>
<email>myemail@gmail.com</email>
<Products>
<Product>
<Product_Id>242</Product_Id>
</Product>
<Product>
<Product_Id>425</Product_Id>
</Product>
</Products>
</Order>
<Order>
<email>youremail@gmail.com</email>
<Products>
<Product>
<Product_Id>657</Product_Id>
</Product>
<Product>
<Product_Id>789</Product_Id>
</Product>
</Products>
</Order>
</Orders>
myemail@gmail.com
242
425
youremail@gmail.com
657
789
PHP代码:
<div class="container" style="padding: 30px;">
<form action="" method="post" id="xml-form" enctype="multipart/form-data">
<label for="xml-text" style="line-height: 40px; font-size: 20px">XML Code:</label>
<br>
<textarea id="xml-text" name="xml-text" rows="30" cols="150" style="font-size: .8rem; letter-spacing: 1px; padding: 10px; line-height: 1.5; border-radius: 5px; border: 1px solid #ccc; box-shadow: 1px 1px 1px #999;"></textarea>
<br>
<input id="xml-sumbit" name="xml-sumbit" type="submit" value="Submit" style="margin-top: 20px; background-color: white; border-color: black;">
</form>
</div>
<span id="test"></span>
<?php
if (isset($_POST['xml-sumbit']) && !empty($_POST["xml-text"])) {
header('Content-Type: text/plain');
print_r(explode("<Order>", $_POST["xml-text"]));
}
XML代码:
请共享您需要的代码以避免输出,您的浏览器正在将
解释为HTML。调试代码的方式几乎肯定会误导您。如果您什么也不做,PHP将保持XML的原样;如果您使用SimpleXML解析它,它将变成一个允许您访问它的对象,并且仍然可以返回原始XML。@SiebeJongebloed如果我添加了另一个示例代码,请检查。@AlexHowansky如何转义输出?