A working Microformats extension to SimpleXML
ExtendXML) that inlcludes all the functionality of SimpleXML.
Download the following to try it out:
The object is created the same way as ExtendXML. After creating it you must also call:
// $mf is a MicroformatXML object
$mf->mf_init();
This adds a new property, $mfHCards, which is an array of hCards. You can access the various hCard values as properties of these objects. As an example:
$mf = MicroformatXML::create_from_file($xmlFile);
$mf->mf_init();
foreach ($mf->mfHCards as $hCard) {
print $hCard->fn .'';
}
Please note this is a very early version that is undocumented and largely untested. It also doesn't contain every hCard property.
Extending SimpleXML
problems with extending SimpleXML (which I intend to do so I can add automatic microformat support). Well I think I’ve come up with a solution.
I’ve created a class called ExtendXML that is completely extendable (see the other post for an explanation of why SimpleXML isn’t extendable) that provides all of the functionality of SimpleXML.
The initial call is similar to using SimpleXML (except I made the functions static class methods instead):
ExtendXML::load_string($xmlString, [$class, [$simpleClass]]);
ExtendXML::load_file($xmlFile, [$class, [$simpleClass]]);
The $class argument contains the name of the class that will be returned. This should extend ExtendXML and defaults to ExtendXML.
The $simpleClass argument contains the name of the SimpleXML class that will be passed to SimpleXML functions. This should extend SimpleXMLElement and defaults to SimpleXMLElement.
The object returned can then be used the same as a SimpleXMLElement object.
I haven’t tested it much or documented it yet, but it supports child tags (returning objects are of the class ExtendXML or whatever you specified), attributes and xpath expressions.
Google Adwords CPM campaigns
So far the CPC campaign is producing more traffic, but it's costing me on average 18¢ per click whereas the CPM campaign is only costing me 4¢ per click.
I think because of my very selective targetting I've managed to find a site that has visitors looking for what I'm advertising, but not offering competition (hence a higher CTR and lower effective CPC).
PHP5 book review
PHP 5 Objects, Patterns, and Practice
Put simply, after reading this book I finally “got” how to use OOP usefully in a web application. Too many OOP tutorials use examples of objects too abstract and literal to be useful (like animals or shapes). This book takes real world examples and explains what sort of things really should be objects and how to use them.
The book is basically split into three sections, as the title suggests. The first part is a very quick overview of OOP and the new features of PHP5. This is thankfully short (and as such this book is aimed at people with a fair bit of PHP experience).
The second section is the largest and basically goes through the most common design patterns and explains situations you’d use them in.
The third section is less focused on OOP and covers some practical considerations including version control and unit testing.
I would say this is probably the best book I’ve bought (except my first Perl/CGI book) and I recomend it for anyone who has to yet to be conviced about PHP as a robust OOP language.
Issues with extending SimpleXML
extend SimpleXML to support microformats. Well it’s not as it easy as it seems.
You can’t define new properties of a class extending SimpleXMLElement. Well you can define them but they don’t work – when you access them they always return a SimpleXMLElement object (or actually an object of whatever class you defined).
I’ve tried overriding __get and __set and neither work so the only thing I can think of is to create a new class that delegates most of it’s work to SimpleXMLElement.
