PHP5

Brushing up a little on some of the things available in PHP5. Here’s something that made me weep happy tears. Given the XML file:

<people>
    <person>
        <name>Daryl L. L. Houston></name>
        <coolness>100%></coolness>
    </person>
    <person>
        <name>Steve Urkel></name>
        <coolness>-100%></coolness>
    </person>
</people>

And the code:

<?php

$people = simplexml_load_file('test.xml');
foreach($people->person as $person){
        print $person->name . ' (' . $person->coolness . ')' . "\n";
}

?>

You get the output:

Daryl L. L. Houston (100%)
Steve Urkel (-100%)

No iterating over arrays, no finding the right PEAR class and making sure you’ve got the right versions of dependent PEAR classes installed. It Just Works™.

I’ve more or less avoided PHP5 to date, as much of the code I write wouldn’t benefit a great deal from many of the things I understand PHP5 to provide, but this alone makes it worth a second glance.

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 )

Connecting to %s