PHP question - what's this mean?

Miscellaneous Forums/General Discussion/PHP question - what's this mean?

I'm just getting my head around parsing XML from PHP with SimpleXML and using something I don't fully understand.

$xml = simplexml_load_file('myfile.xml');
foreach ($xml->TopLevel->NextLevel->AnotherLevel as $result)
  {
    echo $result->Field1;
  }

I kinda understand what the "->" is for - an equivalent of "." in Blitzmax I guess you'd call it, but it does feel a bit cumbersome. Is there another, cleaner-looking way of achieving the same result?

Or am I just doing it completely wrong (it *does* work, though!)?

Recursive functions might be the way to go, a function that calls itself.

You might also want to take a look at json (json.org). It's similar to XML, but simpler and maps more directly to data. It's also smaller, if bandwidth is an issue. Though it's likely your server won't have the json libraries installed. XML has kind of become the default choice for a lot of things, even things it's not suited to do. :)

I'm not sure how that library works (I havent used it) but -> is used to access fields of a instance (like bmax's ".")

So it looks like its reading a xml sheet's nodes. And whatever class your using has a field with another class which also has another field with a class... and so on.


<toplevel>
<nextlevel>
<another level>
blah
</another level>
</nextlevel>
</toplevel>


Yep in PHP "->" is the equivalent of "." in Blitzmax...

I really like PHP, its really powerful... but sometimes it gives me headaches when reading it, as I am use to the syntax of Java and Blitzmax.

Why did they make the string concatenation operator a period (".")!!?!

Dunno but I'm pretty sure Visual Basic was the same? Its been a while though, could be wrong.

Anyhoo, just had a lengthy and helpful chat with misterx (does he post here?) about PHP and XML parsing and the like and I've got a pretty good idea of what I'm doing now.

Been wondering how best to extract data from an XML file and established that the best way is to regularly run a cron job to copy the changes to the XML file into an SQL database.

Works for me, I'm comfortable with MySQL.

Dunno but I'm pretty sure Visual Basic was the same?
I believe it is limited to the C languages (VB uses the period?)

VB uses the period?
Yep, that's what I meant.

Yep, that's what I meant.
Mmmkay..

I believe it is limited to the C languages (VB uses the period?)
C actually uses both. . to access structure members and -> to access members through a pointer to the struct.