How to convert xml file to php array?

I’ve got strange xml file like this http://plk.pl/tmp/tabela.xml, and I don’t know how to convert it into an array. I tried something like this:

<?php
$get = file_get_contents('http://plk.pl/tmp/tabela.xml');
$arr = simplexml_load_string($get);
$data = $arr -> druzyna;
?>
<table>
    <tr>
        <th>pozycja</th>
        <th>pkt</th>
        <th>mecze</th>
        <th>zwyciestwa</th>
        <th>porazki</th>
        <th>wygrane w domu</th>
        <th>przegrane w domu</th>
        <th>wygrane na wyjezdzie</th>
        <th>przegrane na wyjezdzie </th>
        <th>kosze zdobyte</th>
        <th>kosze stracone</th>
        <th>stosunek zdobytych punktów do straconych punktów</th>
        <th>pelna nazwa klubu</th>
        <th>logo klubu</th>
    </tr>

    <?php foreach($data as $row) : ?>
    <tr>
        <td><?php echo $row->pozycja ?></td>
        <td><?php echo $row->pkt ?></td>
        <td><?php echo $row->mecze ?></td>
        <td><?php echo $row->zwyciestwa ?></td>
        <td><?php echo $row->porazki ?></td>
        <td><?php echo $row->wygrane_dom ?></td>
        <td><?php echo $row->przegrane_dom ?></td>
        <td><?php echo $row->wygrane_wyjazd ?></td>
        <td><?php echo $row->przegrane_wyjazd ?></td>
        <td><?php echo $row->kosze_zdobyte ?></td>
        <td><?php echo $row->kosze_stracone ?></td>
        <td><?php echo $row->stosunek_zdob_strac ?></td>
        <td><?php echo $row->pelna_nazwa ?></td>
        <td><?php echo $row->logo; ?></td>
    </tr>   
    <?php endforeach;?>
</table>

but it’s not working.

I read something about json solution, but i don’t know how to use it, however I met first time xml format like that.

I think that this topic How to convert xml into array in php? isn’t solution of my problem, because i’ve got another xml file..

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s