douchuituo3032 2015-10-07 15:07
浏览 42
已采纳

从mysql中检索xml文件并将其用作php中的变量

I'm retrieving an XML code from the database and storing it as a variable in php. However when I try to use this variable inside an XML code, it gives me an error. Here is my code:

<?php

          $conn = mysqli_connect('localhost', 'root', '', 'thisdatabase');
          $result = mysqli_query($conn, 'SELECT * FROM createdproduct');
          while ($row = mysqli_fetch_assoc($result))
          {
            //$selected = (isset($_POST['list']) && $_POST['list'] ==  $row['id']) ? 'selected' : '';
              //echo htmlentities($row["productURL"]);
              $test = htmlspecialchars($row["productURL"]);
          }


          //echo htmlentities($test);
?>

and this is my XML wrapped in php:

<?php
//some code

    $xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <order xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://api.mydomain.net">
        <orderItems>
            '.$test.'
        </orderItems>
        <payment>
            <type>typ</type>
        </payment>
<shipping>
    <shippingType id="00"/>
     <address type="private">
        <person> <
            <salution id="1"/>
            <firstName>person</firstName>
            <lastName>person</lastName>
        </person>
        <street>street</street>
        <houseNumber>00</houseNumber>
        <city>city</city>
        <country code="US">USA</country>
        <state code="mm">California</state>
        <zipCode>111</zipCode>
        <email>aaa@mydomain.net</email>
        <phone>+49 341 789 123</phone>
        <fax>+49 341 789 123</fax>
    </address>
</shipping>
    </order>';
//some code

?>
  • 写回答

2条回答 默认 最新

  • dsgft1486 2015-10-08 10:35
    关注

    I was able to get the result I wanted using html_entity_decode. Thank you

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程