Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [XML][PHP]Znak równości, Dziwny problem
Meferot
post 17.05.2011, 09:51:03
Post #1





Grupa: Zarejestrowani
Postów: 64
Pomógł: 0
Dołączył: 31.08.2009

Ostrzeżenie: (0%)
-----


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:
  1. $monsterCount = count($xml->spawn[$i]->monster);
  2. if($monsterCount > 0) {
  3. for($y = 0; $y < $monsterCount; $y++) {
  4. $monster[$y] = $xml->spawn[$i]->monster[$y]->attributes()->name;
  5. if($y > 0) {
  6. $string = $monsters;
  7. $find = $monster[$y];
  8. $pos = strpos($string, $find);
  9. if($pos == true) {
  10. $monsters = $monsters."taki już był";
  11. }
  12. else $monsters = $monster[$y];
  13. }
  14. else $monsters = $monster[$y];
  15. }
  16. }

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:
  1. <spawn centerx="481" centery="509" centerz="2" radius="1">
  2. <monster name="Undead Dragon" x="-1" y="-1" z="2" spawntime="60"/>
  3. <monster name="Undead Dragon" x="0" y="-1" z="2" spawntime="60"/>
  4. </spawn>
  5. <spawn centerx="475" centery="516" centerz="2" radius="1">
  6. <monster name="Undead Dragon" x="0" y="-1" z="2" spawntime="60"/>
  7. <monster name="Undead Dragon" x="1" y="1" z="2" spawntime="60"/>
  8. </spawn>
  9. <spawn centerx="701" centery="656" centerz="2" radius="1">
  10. <monster name="Giant Spider" x="0" y="-1" z="2" spawntime="60"/>
  11. <monster name="Giant Spider" x="1" y="1" z="2" spawntime="60"/>
  12. </spawn>
  13. <spawn centerx="958" centery="749" centerz="2" radius="5">
  14. <monster name="Orc Berserker" x="2" y="-1" z="2" spawntime="60"/>
  15. <monster name="Orc Leader" x="-3" y="0" z="2" spawntime="60"/>
  16. <monster name="Orc Warlord" x="-1" y="0" z="2" spawntime="60"/>
  17. <monster name="Orc Warlord" x="1" y="2" z="2" spawntime="60"/>
  18. </spawn>


Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 13:49