我想使用PHP将一些数据添加到XML文件中。我很新,所以不太了解术语,所以会尽量解释它。 谢谢 乔
XML文件:
<?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>
答案 0 :(得分:1)
这应该可以解决问题:
// 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');
答案 1 :(得分:0)
尝试使用PHP SimpleXML
The SimpleXML usage page提供了一个如何使用它的好教程。
答案 2 :(得分:0)