Archive for August, 2008

HTML DOM and easy screen scraping in PHP

Friday, August 29th, 2008

One of my favourite features in JavaScript is its ability to interact with the DOM so easily. This is made even easier by various JavaScript libraries and their selector engines largely based on CSS expressions.
Working with XML is easy in PHP with various extensions such as SimpleXML, however unfortunately HTML is far more tedious. Thankfully however, I found this; PHP Simple HTML Dom parser (they could really do with a shorter name! I’ll go for PSDP).
It is a open source PHP solution to DOM parsing, from the documentation it seems to be based on jQuery. So, if your familiar with [...]

CSS Floats and Container Height

Tuesday, August 26th, 2008

<edit>
As pointed out by rborn in the comments below a better way is to simple set the container overflow css property to “auto”. This does the job for you and is a bit tidied that the following solution. However, it might still be use to some of you anyway as it describes the clear property in CSS.
</edit>
It’s been a while since I think I’ve learned something new in the CSS world. So I’m glad to have been recently taught something by a friend.
The problem
For simplicities sake, I’ll just discuss DIV’s. When you make a DIV float (DivB) and its inside [...]

PHP __call and __callStatic Magic methods

Sunday, August 24th, 2008

This is just a quick post to show the use of the magic methods __call and __callStatic. It’s following on in my Magic Method series. The concept is very similar to __set/__get, basically PHP attempts to call a method on a class, if it doesn’t exist the __call method is invoked (if it does exist). __callStatic is exactly the same but with static method calls.
Note that __callStatic will only be available from PHP 5.3 onwards.
Here is a quick example to show it in use;

<?php

// This example assumes ayou already have a DB connection

// established and a database has been [...]

New Design!

Friday, August 22nd, 2008

I’ve just gone live with a new website design. What do you think? I think its much easier on the eyes and also displays code listings much better in the blog!
If your an RSS reader your missing out on all the excitment, so why not pop by for a look?

Creating RSS feeds with SimpleXML

Friday, August 22nd, 2008

I love RSS feeds. One just needs to take a look at my Google Reader to see that;

One of the best things about them is just how easy they are to make. Here is a quick example with PHP showing how you can create RSS feeds with the PHP5 module SimpleXML.

<?php

 

$items = array(

    array(

        "title" => "example",

        "pubDate"=>2,

        "link"=>"http://www.dougalmatthews.com"

        "description"=>"post content")

);

 

header("Content-type: text/xml");

 

$rssName = "My RSS Feed";

$rssHomePage = "http://www.dougalmatthews.com/";

$description = "My RSS feed description";

 

$sxe = simplexml_load_string("<rss version=\"0.91\">

<channel>

    <title>$rssName</title>

    <link>$rssHomePage</link>

    <description>$description</description>

</channel>

</rss>");

 

foreach($items as $item){

    [...]