Taaak, to ja poproszę tutaj o pomoc. Chodzi o skrypt który by wyciągał informacje z pliku a dokładniej z jego środka i potem pokazywał by go w tabelce smile.gif

Tutaj dam przykład:
Mam plik houses.xml:
Kod
<house name="Great Street I">
<tiles fromx="137" fromy="29" fromz="7" tox="143" toy="31" toz="6"/>
</house>
<house name="Great Street II">
<tiles fromx="145" fromy="29" fromz="7" tox="151" toy="31" toz="7"/>
</house>
<house name="Great Street III">
<tiles fromx="155" fromy="29" fromz="7" tox="159" toy="32" toz="7"/>
</house>
<house name="Great Street IV">
<tiles fromx="165" fromy="33" fromz="7" tox="169" toy="39" toz="7"/>
</house>
<house name="Upper Street I">
<tiles fromx="155" fromy="29" fromz="6" tox="163" toy="33" toz="6"/>
</house>

A teraz skrypt pobiera informację z pliku i wyświetla nazwę, ilość kratek(o tym za moment) i cenę(poniżej).

Na ilość kratek składa się wzór:
Cytat
<tiles fromx="155" fromy="29" fromz="6" tox="163" toy="33" toz="6"/>

Czyli:
tox minus fromx, toy minus fromy, toz minus fromz+1
teraz wyniki działań mnożymy i wychodzi nam liczba kratek a skrypt to wyświetli.

Cenę obliczamy: liczba kratek razy $cena która zdefiniowana jest w config.php.

Pamiętać że to jest jeden domek a skrypt ma wyświetlić wszystkie. Więc może punktem oddzielającym jeden domek od drugiego będzie tag </house> ? Nie wiem. Wasza wola. Aha, no i żeby była zmienna na ścieżkę do tego pliku smile.gif.Napisałem podobny skrypt ale on nie liczy kratek a potem kosztów więc nie wiem. A może mi naprawicie stary kod zamiast pisać nowy?
Oto kod:
  1. <?php include ('top.inc.php');?>
  2. <?php include 'config.php'; ?>
  3.  
  4. <? 
  5.  
  6. $dir = 'sciezka'; //localization to folder data in ots
  7.  echo '<table align="left"><tr><th align="left">Name:</th><th>Tiles</th><th>Price</th><th align="left">Owner</th></tr>';
  8.  $f = @fopen($dir.'houses.xml', 'r');
  9.  $contents = fread($f, filesize($dir.'houses.xml'));
  10.  $tags = explode('<', $contents);
  11.  $i = 0;
  12.  foreach($tags as $tag) {
  13. if(substr($tag, 0, 5) == 'house') {
  14.  if($temppos = stristr($tag, 'name="')) {
  15. $i++;
  16. $temp = explode('"', $temppos);
  17. $name[$i] = $temp[1];
  18.  }
  19. } elseif(substr($tag, 0, 5) == 'tiles') {
  20.  if($temppos = stristr($tag, 'fromx="')) {
  21. $temp = explode('"', $temppos);
  22. $fx = $temp[1];
  23.  } elseif($temppos = stristr($tag, 'fromy="')) {
  24. $temp = explode('"', $temppos);
  25. $fy = $temp[1];
  26.  } elseif($temppos = stristr($tag, 'fromz="')) {
  27. $temp = explode('"', $temppos);
  28. $fz = $temp[1];
  29.  } elseif($temppos = stristr($tag, 'tox="')) {
  30. $temp = explode('"', $temppos);
  31. $tx = $temp[1];
  32.  } elseif($temppos = stristr($tag, 'toy="')) {
  33. $temp = explode('"', $temppos);
  34. $ty = $temp[1];
  35.  } elseif($temppos = stristr($tag, 'toz="')) {
  36. $temp = explode('"', $temppos);
  37. $tz = $temp[1];
  38.  }
  39.  if (isset($tiles[$i]))
  40. $tiles[$i] = $tiles[$i] + (($tx - $fx) * ($ty - $fy) * ($tz - $fz + 1));
  41.  else
  42. $tiles[$i] = ($tx - $fx) * ($ty - $fy) * ($tz - $fz + 1);
  43. }
  44.  }
  45.  for ($a=1; $a<$i; $a++) {
  46. $cena = $tiles[$a] * 250; //you can change 250 to count of gps for one sqm
  47. if ($cena > 1000) {
  48.  $cena = $cena / 1000;
  49.  $cena = $cena.'k';
  50. } else
  51.  $cena = $cena.' gp';
  52. $f = @fopen($dir.'houses'.$name[$a].'.xml', "r");
  53. $contents = fread($f, filesize($dir.'houses'.$name[$a].'.xml'));
  54. $just = explode('<', $contents);
  55. foreach($just as $jus) {
  56.  if(substr($jus, 0, 5) == 'owner') {
  57. if($temppos = stristr($jus, 'name="')) {
  58.  $tem = explode('"', $temppos);
  59.  $nick = $tem[1];
  60. }
  61. if(empty($nick))
  62.  $owner = '<b>Nobody</b>';
  63. else
  64.  $owner = $nick;
  65.  }
  66. }
  67. print '<tr><td>'.$name[$a].'</td><td align="center">'.$tiles[$a].'</td><td align="center">'.$cena.'</td><td align="left">'.$owner.'</td></tr>';
  68.  }
  69.  print '</table>';  
  70. ?> 
  71.  
  72. <?php include ('menu.inc.php');?>


Jeżeli ktoś nie rozumie to mu wytłumacze smile.gif. Nie bijcie za kod, dopiero się ucze.