duanpaotian2348 2015-07-18 18:12
浏览 23
已采纳

使用PHP将数据添加到XML文件

I would like to add some data to a XML file using PHP. I'm quite new and so do not know much of the terminology and so will try to explain it as much as possible. Thanks Joe

XML FILE:

<?xml version="1.0" encoding="UTF-8"?>
<music>
    <song>
        <title>Example Song</title>
        <album>A Album</album>
        <artist>A Artist</artist>
        <length>3.41</length>
    </song>
//The New Song I Would Like To Add For Example
    <song>
        <title>Another Example Song</title>
        <album>Another A Album</album>
        <artist>Another A Artist</artist>
        <length>Another 3.41</length>
    </song>
//The End Of The New Song I Would Like To Add

</music>
  • 写回答

3条回答 默认 最新

  • ds78662302 2015-07-18 18:38
    关注

    I haven't tested that but I think that it would be work

    With SimpleXML

    // Read file    
    $music = simplexml_load_file('music.xml');
    
    $character = $music->addChild('song');
    $character->addChild('title', 'Another Example Song');
    $character->addChild('album', 'Another A Album');
    $character->addChild('artist', 'Another A Artist');
    $character->addChild('length', 'Another 3.41');
    

    And then force download the new file

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

报告相同问题?

悬赏问题

  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答