TobyInkster.co.uk

Articles Tagged with “Oop”

20/07/2007: Parsing an HTML Table with PEAR’s XML_HTMLSax3

Here’s an example of how to parse an HTML table into an array using the PEAR module XML_HTMLSax3. It supports the <tr>, <td> and <th> elements and the rowspan and colspan attributes…

19/07/2007: PHP Domain Class

On Usenet an often-asked question is how to programmatically determine the “domain” of a particular hostname. That is, excluding the components traditionally thought of as subdomains. As an example, groups.google.com and www.google.com both have a domain of google.com.

Invariably, one answer comes back stating that you just need to chop off everything from the front, leaving only the last two components. But then someone will chime in pointing out that groups.google.co.uk would be left as just co.uk that way, when what is really wanted is google.co.uk. And the eventual resolution of the argument will be “it just can’t be done”.

The problem is that there’s technically no difference between a domain and a subdomain: it’s simply a matter of convention. Fortunately, this issue is actually quite important to browser programmers, as it’s a key issue in cookie security: browsers must allow subdomains within a domain to share cookie data, but not allow cookies…

19/12/2006: On The Legibility of PHP

David Segall wrote:

I do not deny that the programmer is the most significant factor in the readability of a program but would you really promote PHP as a language because it is easy to read?

I certainly wouldn’t advise against it because of legibility concerns.

Any language that supports comments (not all do) and allows the programmer to choose variable and function identifiers using arbitrary alphanumeric names (again, not all do) can be made very readable simply by using these facilities. With most common programming languages, you can easily clarify your code by having a policy that includes choosing sensible, readable function and variable names, using indentation and plenty of white space, adding liberal comments, keeping line lengths down to a reasonable length, keeping function sizes down to 20 or so lines (longer functions can often be split into two or more functions). Yes, even Perl!

For example, consider the following two (untested) PHP objects which are exactly…

Google Search

Blogroll

Here are some other sites. Some might be good; some might be rubbish. You decide.