Jump to content

Parse XML to a php page help please


Kibit

Recommended Posts

I have to be honest, I have absolutely no idea how to go about this but I think for someone who's done this sort of thing before I'd be a 2 sec doddle of a job.

 

I want to pull some info (but not all) out of an XML file

 

Here is the file..

http://www.wsad.co.uk/tm/ajax.php?plugin=Website&autologin=true&server_id=1

 

And all I wanna pull out is

<name>

<type>

<currentchallenge>

<players>

 

If someone could code that in php with a plain text output I would be extremely grateful.

Link to comment
Share on other sites

Take a look at the simplexml extension. It really is, as the name implies, simple.

 

Thanks but it seems not simple enough for a n00b like me..

 

Here is what I've done..

 

<?php

$xml = http://www.wsad.co.uk/tm/ajax.php?plugin=Website&autologin=true&server_id=1;

echo $xml->name[0]->plot; // "So this language. It's like..."
?>

 

And I get

Parse error: syntax error, unexpected ':' in /home/wsad/public_html/tm/test.php on line 3

 

If someone could just get me started with a basic working bit of php I'm sure I'll be able to work it out.

Link to comment
Share on other sites

I now have a basic working page using the following code...

 

<?php

$xml = simplexml_load_file("http://www.wsad.co.uk/tm/ajax.php?plugin=Website&autologin=true&server_id=1");


echo $xml->getName() . "<br />";

foreach($xml->children() as $child)
  {
  echo $child->getName() . ": " . $child . "<br />";
  }
?>

 

The page is here..

http://www.wsad.co.uk/tm/test.php

 

But as you can see that just outputs everything and I only want to show a couple of the details as outlined in the first post, Also where there are more than 1 result (I think its called an "array") such as...

 

<players>
−
<item>
<span class='tm-b'>[WSAD]<span style='color:#0f0'>Harding</span></span> 
</item>
</players>

 

Its not returning any results.

 

Any further help would be very gratefully received and since I noticed your on a donation drive I could be convinced to donate ;-)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.