将所有数据(数字)添加到';点';使用php从xml文件中删除节点
我使用的是xml文件,例如:将所有数据(数字)添加到';点';使用php从xml文件中删除节点,php,xml,replace,add,Php,Xml,Replace,Add,我使用的是xml文件,例如: <result> <team> <name>arsenal</name> <games>4</games> <points>12</points> </team> <team> <name>chelsea</
<result>
<team>
<name>arsenal</name>
<games>4</games>
<points>12</points>
</team>
<team>
<name>chelsea</name>
<games>4</games>
<points>6</points>
</team>
<name>arsenal</name>
<games>5</games>
<points>8</points>
</result>
兵工厂
4.
12
切尔西
4.
6.
兵工厂
5.
8.
使用php,我想为阿森纳添加分数(12和8)……或者有没有更好的方法,而不是添加分数,因为我将它们放在xml文件中,我可以替换阿森纳并更新细节,例如游戏和分数,我可能会这样做:
<?php
$string = <<<XML
<result>
<team>
<name>arsenal</name>
<games>4</games>
<points>12</points>
</team>
<team>
<name>chelsea</name>
<games>4</games>
<points>6</points>
</team>
<team>
<name>arsenal</name>
<games>5</games>
<points>8</points>
</team>
</result>
XML;
$xml = new SimpleXMLElement($string);
$result = $xml->xpath('//team//name[.= "arsenal"]/..');
$points = 0;
foreach ($result as $node) {
$points += $node->points;
}
echo "SCORE = " . $points;
xpath('//team//name[.=“阿森纳”]/..);
$points=0;
foreach($result作为$node){
$points+=$node->points;
}
echo“SCORE=”$点数;
非常感谢,我可以再问一个问题吗?我在表格上显示了我的结果,但我希望结果按(最高-最低)顺序排列,有什么想法吗??另外,非常感谢前面的问题,它对我帮助很大