Main Content

Learning to program in PHP - Regular Expression and Associative Array examples

Archive - Originally posted on "The Horse's Mouth" - 2011-12-01 23:13:04 - Graham Ellis

There's a lot to learn on a week-long PHP course - especially if you're new to programming. And delegates need practice during and after the course with some relatively straightforward (but rewarding) real applications. One of the things that we do ourselves is to analyse server log files - allowing for us to research and learn from the traffic arriving at out web site. Such data and feedback is important when you're considering search engine placement, and it's a rewarding application to write too as a short piece of code can tell you a very great deal. In the past, you might have used analog or AWStats for analysis like these. Nowadays many people use Google Analytics but some elements there have become paying services, and a "do it yourself" approach does let you fine tune at the grass roots too.

I've added two demonstrations to our web site from today. The first counts the number of accesses to each page in a log file, and reports on the 10 most visited - source code [here].

The second also shows reglar expressions and associative arrays, but I have extended it to look at the search terms used and report on each of those for the most arrived-at three pages. That's done using an array of arrays (you may consider that to be a two dimensional array if you wish, but really it isn't). And the source is commented - see [here]. You can also run that code (and it will look at accesses from 03:30 until the current time - live data) [here].

As ever, the really useful information can come in the trimmings, and I've added a link from each of the arrival pages into this last demo so that it forms a really useful too for your SEO team ... not bad for something written on the penultimate day of your first programming course!




Next PHP course - February 2012. Some places remain. Whether you're reading this article in time for the February course, or not, you can find full details of all our PHP courses and upcoming dates [here]. Courses are taught interactively so that you don't just see the programs - you see how they're developed too, and groups are limited to eight delegates to make sure that everyone gets plenty of help and tutor time if they need it. We even have our own hotel rooms if you're coming from a distance so you can stay with us!