PHP

  1. Using PHP Functions in XPath Expressions

    Disclaimer: this article expects familiarity with using the DOM1 extension and XPath2 expressions.

    The (currently undocumentednow documented3) DOMXPath::registerPHPFunctions method is available as of PHP 5.3.0 (it was added to the code base back in December 2006) and allows the use of PHP functions (and static methods) within XPath queries to complement the normal set of XPath functions2.

  2. The InfiniteIterator in PHP

    In an article back in July (Anonymous Functions and Closures (as of PHP 5.3)), I gave an example of looping over a series of values repeatedly. Whilst that example does the job (and introduces the concept of closures) it’s hardly the most convenient method of repeatedly iterating over a series of values. Introducing the InfiniteIterator which is part of the Standard PHP Library (SPL).

  3. What Firefly/Serenity Can Teach Us About PHP (external)

    This update is just really linking through to What Firefly/Serenity Can Teach Us About PHP on PHP Developer where the author makes some comparison between the awesome sci-fi series Firefly and PHP. Worth a few minutes at least: go read.

  4. Anonymous Functions and Closures (as of PHP 5.3)

    There has been much discussion, especially of late considering the release of PHP 5.3, on the subject of anonymous functions and closures (both terms appear to be used interchangeably in the documentation). They are not the same, though many folks are introduced to them at the same time.

  5. PHP 5.3.0 Released

    Today the latest stable version of PHP was announced, PHP 5.3.0.

    Go download and play with the new features available such as namespaces, LSB, anonymous functions and closures along with many more bug fixes, additions and improvements.

  6. Parsing Dates with DateTime

    This post comes on the back of a number of forum posts I’ve seen floating around where the Original Poster (OP) asks a question along the lines of, “I have a date in dd/mm/yyy format, how can I work with it?

    The problem is that the most common way of parsing strings into a more usable format (Unix timestamp) is to use strtotime(). However, this function does not like dd/mm/yyyy formatted strings and will at best parse the string as mm/dd/yyyy and at worst return FALSE (if it could not parse the date string as mm/dd/yyyy).

  7. Joined the PHP Documentation Team

    PHP logo This is just a very short update to announce quietly that I recently joined the team of folks working on the PHP documentation. It’s another step towards giving a little something back to the PHP community by adding to and updating the constantly evolving docs which have helped me along for so many years. Incidentally, my first commit was too large to be sent out to the mailing list tracking the changes to the documentation. Oops!

  8. Kohana 2.3.3 (and 2.3.4) Released

    Recently the guys over at Kohana flicked the switch on the latest release: version 2.3.3. There have been many changes and improvements along the way (see the 2.3.3 changelog for details). I just want to send a big thanks to everyone who donates their time into developing the framework that I use all of the time. Thanks!

    This will be the last version on the 2.3 branch with forward movement pushing ahead with 2.4 (coming with new and improved features) and of course Kohana 3 is also being very actively developed.

    Update Only a couple of days later, 2.3.4 has also been unleashed to the public. :)

  9. Modal value(s) in PHP

    I was browsing around the website of someone on IRC and found that they had written a function to determine the mode of an array of values. The function seems a little convoluted so in a spare 15 minutes I decided to re-implement it, take care of some of its caveats and make a quick blog post, the one you see here.

  10. Time-based Twitter Theme

    Early this morning, I got the urge to change the twitter theme for my profile. There’s nothing strange in that, except perhaps that acting on urges seems to be common for me recently.

    I was bored of the normal fancy-graphic-background-on-the-left style of themes and wanted to go simple but with a twist. Instead of the usual, something unusual was the order of the day. Quite what, I didn’t really now.

  11. PHP Advent

    Ok, this is a little late since today’s the 17th (and very nearly the 18th for me) but there’s a lovely series of articles, or “doses of widsom”, covering a range of topics including the PHP community, web services, documentation, frameworks, JSON, MySQL and the development of PHP being offered up in the form of PHP Advent. In their own words:

    Christmas is nigh, and the PHP Advent Calendar rides again! In line with tradition, we’ve swapped the chocolates for doses of wisdom from people in the PHP community who’ve kindly donated their thoughts and tips to see us through the coming year. Enjoy!

    I’ll be keeping an eye out for the remaining doses of wisdom over the coming days and invite you to do so as well! Once again, it’s phpadvent.org (bookmark it, Google Reader it, or just remember to visit it daily). Happy holidays to all. :)

  12. Server download speed using PHP cURL

    I’ve been meaning to add a few snippets of code to the blog, just to archive them to save my own memory but who knows, they may prove useful to someone else.

    This particular one uses cURL to get an idea of the download speed of your web server but is more a demonstration of grabbing the extra information about a cURL transaction which people rarely take a look at. The code was first posted in a similar topic on Sitepoint.

  13. PHP Imagecreate & Different File Types

    For a recent little bit of PHP scripting, I wanted to grab an image off of a remote server (not for any nefarious purpose!) and manipulate it in PHP (with GD).

  14. PHP Get File Extension

    Over time, I’ve seen a wide range of scripts which for one reason or another have had the need to grab the extension from a file name or path (E.g. “gif” from “mypic.gif”). Oftentimes the solution tends to fall back on what the task appears to need: string manipulation. Though, as you’ll see, this may not be the best approach to take.

  15. PHP Variable Names: Curly Brace Madness

    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 frown on it:

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

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

  16. PHP Variable Switching – How not to do it!

    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!

  17. TalkPHP: Part 2 – Currency Converter with Automatic Conversion Rates via XML

    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

  18. PHP5 Method Chaining

    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();
  19. Don’t repeat yourself when using printf!

    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?

  20. APIs in PHP

    I’ve been wanting to sink my teeth into something juicy for a while now. Since I have been working heavily with various web APIs recently (Yahoo Web Services, Google APIs, etc) I figured that it was about time I got with the spirit of open data access.

    Now, I like to dip my feet in gently to new projects so am going to be working with something small (just a few methods) in PHP (why not?) by creating yet another URL shortening website. I’m not expecting it to be a success more just something that I can say, “well, I made this.” Where does the API fit into this? Well, the site itself will be running off of a REST-based API that I will create and will allow anyone else to access the same resources (to make their own url shortener?) through simple REST requests and responses.

    I’ll get into details in later posts probably, this really is just a “hey, I’m doing this” style of post. Before that, I might give some quick and easy examples of consuming popular web services (with PHP), just to get the ball rolling.