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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵