用php更改xml属性

Im trying to create a mp3 player that will add songs per day. So after long search over the net for months. Finally came up with an option, a flash player with a xml file which is controlled by a PHP code determining the date. since this is the first project im doing in PHP im totally lost.

Here is the xml for the flash player which I have downloaded

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <param name="mp3" value="tracks/2.mp3|tracks/1.mp3" />
    <param name="title" value="Day 2|Day 1" />
    <param name="height" value="150" />
    <param name="width" value="250" />
    .........

The first two children's "value" attribute should change per day.

And here is the PHP code I have come up with which doesn't work

$data = simplexml_load_file('tracks/list.xml');
$xml = new SimpleXMLElement($data);

foreach($xml->param[0]->attributes() as $name => $value)
foreach($xml->param[1]->attributes() as $name2 => $value2)

$today=date(d);
if($today==01){
    $value.setAttribute("tracks/1.mp3");
    $value2.setAttribute("Day 1");
    echo $xml->saveXML();
}
if($today==02){
    $value.setAttribute("tracks/2.mp3|tracks/1.mp3");
    $value2.setAttribute("Day 2|Day 1");
    echo $xml->saveXML();
}
if($today==03){
    $value.setAttribute("tracks/3.mp3|tracks/2.mp3|tracks/1.mp3");
    $value2.setAttribute("Day 3|Day 2|Day 1");
    echo $xml->saveXML();
}
.........

Please help me out on how to fix this. Thanks

You can use XQuery to do the job:

let $config := 
<config>
    <param name="mp3" value="tracks/2.mp3|tracks/1.mp3" />
    <param name="title" value="Day 2|Day 1" />
</config>
let $today := day-from-date(current-date())
return
    switch(1)
    case 1 return {
        replace value of node $config/param[1]/@value with "tracks/1.mp3";
        replace value of node $config/param[2]/@value with "Day 1";
        $config
    }
    default return ()

You can try the following example live at http://www.zorba-xquery.com/html/demo#bYJOffXahl2PVhczDk+EgmZ1bAI= Instructions on how to install the XQuery PHP extension are available at http://www.zorba-xquery.com/html/entry/2011/12/27/PHP_Meets_XQuery

It's incorrect. You need SimpleXml, Dom Xml or smthng like. Use xpath to find node and than set attribute, after save xml. Examlpes: http://php.net/manual/en/book.simplexml.php , http://php.net/manual/ru/domelement.setattribute.php