PHP Variable Names: Curly Brace Madness

Posted on January 12th, 2008 in PHP | 6 Comments »

Most PHP coders will know that one is able to specify variable names in the following format, generally within double-quoted strings, however much they from on it:

$str = "Hello ${username}, you look nice today.";

However, that's not the only way to use the brace syntax!

Read the rest of this entry »

PHP Variable Switching - How not to do it!

Posted on January 5th, 2008 in PHP | No Comments »

Over on TalkPHP, there is a wee contest running with the essential idea being to swap around the values belonging to two variables in 8 lines or less. There are very simple, very obvious ways of doing this which you would normally use (I don't think I've ever actually had to swap the values of two variables in real coding!) but for fun, the entire point of the contest is to be creative with the solutions.

We are presented with

$a = 1;
$b = 2;

and quite simply, the aim is to end up with $a having a value of 2 and $b having a value of 1. Easy!

Read the rest of this entry »

TalkPHP: Part 2 - Currency Converter with Automatic Conversion Rates via XML

Posted on December 9th, 2007 in PHP | 2 Comments »

Using SimpleXML to acquire the conversion rates, and storing it in JSON format to be used in the conversion itself. This article introduces some rather impressive functionality to further your PHP skills.

read more | digg story

PHP5 Method Chaining

Posted on September 19th, 2007 in PHP | No Comments »

Introduction

In this article, I'll be talking about a useful new feature introduced in PHP5 as part of the OOP improvements over PHP4. This feature is called Method Chaining and enables us to do pretty cool things like:

$object->method_a()->method_b()->method_c();

Read the rest of this entry »

Don’t repeat yourself when using printf!

Posted on September 17th, 2007 in PHP | No Comments »

Hi folks,

We all use printf (or sprintf) to help ourselves when mingling together output strings with our variables, right? This is a tip that I use often, but I continually see people writing code where this technique would be useful but isn't used. What _am_ I on about? Read the rest of this entry »