Flipflops.org

Four pieces

It’s been a while since I exhibited anything, but I’ve got three new pieces and one old one in the summer show at the Redearth gallery (currently without a decent website unfortunately)

Quick debug function

It’s not pretty and it’s not elegant, but we’ve all got a bag of quick and dirty functions that help make life just a little bit easier.

This is a simple print_r() but I finally got fed up of loosing my quick debug statements and so added the line name and file number from a stack trace (substitute var_export() to taste).

 
function pr($str){
 
        echo('
');
        print_r($str);
        echo('
'
);   $d = debug_backtrace();   echo $d[0]['file'] . '
Line: '
. $d[0]['line'] . ''; echo '
'
;   }

Beer loving blog

Useyourlocal.com (great website if you’re away for the weekend and need to get a drink in a decent pub fast) have just started a blog with the highly imaginative name of blog.

Anyway they’ve just written an article about beer made from weird stuff like stinging nettles. I’ve had omlettes made from nettles and also nettle and wild garlic soup – but never nettle beer. Food for free is one thing (great) – beer for free must be even better.

I think they could be onto a winner. Now that summer is coming and my various sheds have risen above freezing, I might give this home brewing lark a go. There are certainly plenty of nettles round me… and I bet I could do something good with dandelions.

Cheers!

The bathroom crocodile

Telling your a child that if they don’t brush their teeth, then all their teeth will fall out, and / or the dentist will cause them a great deal of pain doesn’t really cut it with a three year old (and is also a questionable approach)

At home we’ve come up with a new strategy. In our bathroom we have a very hungry crocodile, but fortunately he doesn’t like to eat children with clean teeth.

Reorder a nested HTML list in PHP

Recently I was working on website where I had to re-order a nested list (part of a navigation menu) – unfortunately I only had access to fragment of HTML so I couldn’t just manipulate the arrays from which it was built. The menu was compiled from various arrays and months within years sometimes came out all wrong.

So I thought, I’d just treat it as a bit of XML (which obviously it is) and re-order it using PHPs native XML handling classes. XML is one of those things that I use frequently, but never really do anything with, and finding a solution took me rather longer than I had expected. It is a mixture of simpleXML and XMLDom.

One of the main problems was the lack any real examples.

If anyone can suggest a more elegant solution, I would love to hear it.

Here is my code:

The UL to re-order

As you can see the month names are in the wrong order

My (woeful) solution

 
$xml = simplexml_load_string($string);
 
// pull a node tree as an Array out using simpleXML xpath
$trees = $xml->xpath('/ul/li/ul');
 
$array = array();
$order = array();
 
$i = 0;
 
// we only need to delve into XML if there are any nested