Month: February 2010

Simple Twitter API XML Parsing in PHP

A friend asked me the best way to parse XML in PHP. I didn’t have an answer. It doesn’t sound like a weird request but usually the XML parsing is done on the client side(AJAX/Flash/XSL) instead of the server side…..the one usually serving the XML.

Some quick googling led me to believe that this was very monotonous before PHP 5.

Here’s a quick and dirty script to easily traverse some XML.

$xml = simplexml_load_file(“http://twitter.com/statuses/user_timeline.xml?screen_name=shitmydadsays”);

//root
echo $xml->getName() . “
“;

foreach($xml->children() as $status)
{
//status
echo $status->getName() . “: ” . $status . “
“;
foreach($status->children() as $items)
{
echo $items->getName() . “: ” . $items . “
“;
//user
if($items->getName() == “user”){
foreach($items->children() as $user){
echo $user->getName() . “: ” . $user . “
“;
}

}
}
echo ‘———————–
‘;
}

Take this and drop it in a file or download this zip(right click save as) and run it in localhost or on your server.

Missing flash.events package in Flex code hinting

One of the many features you get spoiled with using in Flex Builder is code hinting. Unforunately, this is one of the things that break when you start installing new sdk’s….if you haven’t upgraded your Flex Builder in a while that is. Here’s the link to the upgrade from 3.0.1 to 3.0.2.

If your sdk isn’t finding the flash.events.* package, it will remove them when it goes to clean up your import statements. It also won’t help with code hinting at all, but it will still compile if you manual type in the import. Very annoying, but fixed.