Mam problem z porównaniem dwóch elementów z pliku XML. Próbowałem już na kilkanaście sposobów, jednak za każdy razem skrypt nie dostrzega podobieństwa w rekordach. Teraz próbuje metodą odnalezienia danego elementu w ciągu, mój kod wygląda tak:
$monsterCount = count($xml->spawn[$i]->monster); if($monsterCount > 0) {
for($y = 0; $y < $monsterCount; $y++) {
$monster[$y] = $xml->spawn[$i]->monster[$y]->attributes()->name;
if($y > 0) {
$string = $monsters;
$find = $monster[$y];
$pos = strpos($string, $find); if($pos == true) {
$monsters = $monsters."taki już był";
}
else $monsters = $monster[$y];
}
else $monsters = $monster[$y];
}
}
Chodzi o to, aby skrypt pomijał te elementy które już wcześniej się pojawiły i nie dopisywał ich do zmiennej $monsters.
Fragment pliku XML wygląda tak:
<spawn centerx="481" centery="509" centerz="2" radius="1">
<monster name="Undead Dragon" x="-1" y="-1" z="2" spawntime="60"/>
<monster name="Undead Dragon" x="0" y="-1" z="2" spawntime="60"/>
</spawn>
<spawn centerx="475" centery="516" centerz="2" radius="1">
<monster name="Undead Dragon" x="0" y="-1" z="2" spawntime="60"/>
<monster name="Undead Dragon" x="1" y="1" z="2" spawntime="60"/>
</spawn>
<spawn centerx="701" centery="656" centerz="2" radius="1">
<monster name="Giant Spider" x="0" y="-1" z="2" spawntime="60"/>
<monster name="Giant Spider" x="1" y="1" z="2" spawntime="60"/>
</spawn>
<spawn centerx="958" centery="749" centerz="2" radius="5">
<monster name="Orc Berserker" x="2" y="-1" z="2" spawntime="60"/>
<monster name="Orc Leader" x="-3" y="0" z="2" spawntime="60"/>
<monster name="Orc Warlord" x="-1" y="0" z="2" spawntime="60"/>
<monster name="Orc Warlord" x="1" y="2" z="2" spawntime="60"/>
</spawn>