Exercises, examples and other material relating to training module H999. This topic is presented on public courses
PHP is a powerful language with many exciting capabilities, several of which are supported through function libraries. This module covers some of the more popular additions such as sorting, graphics, XML handling, and using PHP in stand-alone programs. It also covers more advanced language features such as variable typing and multidimensional arrays.
|Articles and tips on this subject||updated|
|4655||Image indexer / thumbnail display scripts in PHP|
I often say that example programs provided to show "how to" become too complex too quickly - going straight from the simplest of programs (a.k.a. a "hello world") though to something much more complex in a single leap. I take multiple steps as I proceed on our courses, and I try to make sure that I ...
|1451||More PHP sample and demonstration programs|
It's amazing how many little (and not so little) new programs and demonstrations I write - here are some from the last couple of days:
• The Melksham / Bowerhill Christmas Quiz, 2007. Ten questions, work out the answers, click on a link at the bottom the page and it will be refreshed to tell you ...
|789||Hot answers in PHP|
We've got a lot - a LOT of demonstrations and source code on our site. Here are a few of the most popular ones all brought together in a single listing. Enjoy ...
Searching - how similar are two words? - try about source
Does a particular URL exist? - try source
Uploading an image to a database ...
|3210||Catchable fatal error in PHP ... How to catch, and alternative solutions such as JSON|
When you ask your program to "print out an object", you're really looking to convert a data structure into a stream of characters, and it's not really obvious what you're looking to do.
If you try to print out an object in PHP:
print ($result . "\n");
where the $result variable contains ...
|1390||Converting from postal address to latitude / longitude|
Do you sometimes find odd gaps in new procedures you follow - "I can see everything I need to do to make X happen, except" ?
I hit one of those yesterday. When learning how to interface to Google maps ... all the information was there, except there was no way that I could spot to click on a map and ...
|3118||Arrays of arrays - or 2D arrays. How to program tables.|
It's shorthand when you're learning a new programming language to ask "how does it handle multiple dimension arrays" ... but in practise very few languages actually support true multidimensional arrays these days, and in those which do you might be well advised to use an alternative that's more flexible.
|2684||Exception handling in PHP|
PHP has exception handling - where you can try a block of code; it it completes, that's good and normal, but if something doesn't work in the normal manner an exception is thrown, and a piece of code to mop up the problem is run, in a catch block.
I've written an example to show this ... I have a function ...
|2215||If nothing, make it nothing.|
Here's a peculiar PHP statement I wrote this morning:
if ($aindex[$chk] == "") $aindex[$chk] = "";
What was I doing? I am actually checking to see whether there's anything in an array element and if there isn't (which could be because it's empty or because it doesn't yet exist), then it ...
|2073||Extra PHP Examples|
Yesterday evening and this morning, I was helping with some specific PHP questions ... resulting in some new examples that I've put on the web site.
• A program which can be used / allows logins only between 3pm and 5pm on a Wednesday afternoon (and could easily be adapted to let people in at breakfast ...
|806||Check your user is human. Have him retype a word in a graphic|
Do you have trouble with automated programs completing forms on your websites and making cart loads of submissions? Or even just a few spammers submitting their betting ads, performance enhancing pill sites, and share purchase suggestions? And yet you don't want to have to have anyone who wants to ...
|1104||Drawing dynamic graphs in PHP|
The web is all about presenting data, and a picture paints a thousand words - so what's better than a graph to quickly and easily present figures and trend to yor web site visitor?
There's a great deal of software available to produce static diagrams and graphs as image files - .gif or .jpg are the ...
|1010||Dates, times, clickable diarys in PHP|
It's that quiet week between Christmas and the New Year that's an excellent chance to catch up - a little - on some of the things that are important but have been abandoned in the mad rush of urgent things these last 9 months. Like writing a booking system and like - I hope - spending long overdue ...
|1389||Controlling and labelling Google maps via PHP|
"Can you use PHP to control what you show on a Google Map?" An innocent question that lead me off on an interesting exploration when I should (!) have been doing other things - but a very worthwhile couple of hours, and great fun!
How do you do it?
1. Apply for your Google Maps key (you'll need to ...
|1391||Ordnance Survey Grid Reference to Latitude / Longitude|
I've already written about conversion of postal addresses to latitude and longitude using Google's interface - but what is I want to convert the Ordinance Survey's grid references into latitude and longitude? Google's interface doesn't support the OS units - and in any case it's "just" a a calculation. ...
|239||What and why for the epoch|
The Epoch occurred on 1st January 1970 ... at midnight, at the start of the day, GMT. It's an important concept in many programming languages, which work with times and dates before and after the epoch - it means that you can compare dates and times easily, even where month ends and different timezones ...
|687||Presentation, Business and Persistence layers in Perl and PHP|
I've been writing about the Presentation, Business and Persistence tiers (and within each of them the MVC or Model, View, Controller or MVC structure) for a JBoss presentation I'm doing this week - but I scarcely expected to find myself putting them to good if unusual use this evening when sorting out ...
|320||Ordnance Survey - using a 'Get a map'|
Sunday, and a chance to play. I've been interested in the possibilities offered by Ordnance Survey's "Get a map" service - which allows (with limitations described on their site) their mapping to be captured and used on web sites in a not-for-profit way.
I've started to put up a whole load of pictures ...
|1485||Copyright and theft of images, bandwidth and members.|
Some poor home school kid in the USA just got the sharp end of my tongue .. I had just signed up to a political forum and so had he (he said) and he wrote:
Also I was wondering if you would join my political forum at http://www.xxx.org .(I know this is an advert but it's really hard to get a new board ...
|1519||Flipping images on your web page|
Are you seeing this picture the right way up, or upside down?
If you're seeing it the right way up, you're using Mozilla, Firefox, Safari, Netscape or almost any other browser ... except Internet Explorer. With Internet Explorer, it might be up side down!
This is no "failure" on the part of some ...
|937||Display an image from a MySQL database in a web page via PHP|
There's lots of clever scripts around to tell you how to get images in and out of databases, but nothing simple to show you the principles of including such an image via (say) PHP in a web page. So here goes.
you need TWO URLs - you need the HTML page that's going to contain the image, AND you need ...
|1623||PHP Techniques - a workshop|
So many people know the basis of PHP - the language constructs themselves and how they work individually - but could really benefit from learning how to make the best of those elements. And these techniques for putting the elements together are so important that they should not be crammed onto the end ...
|1505||Script to present commonly used images - PHP|
"What are the most popular pages in your picture library, and where are they used from?" An interesting question and I could analyze raw web logs to find out the answers. However, most of our images are managed by a script that retains extra information such as an image title, and uses are logged ... ...
|1270||PHP Standalone - keyboard to screen|
PHP is a web language. Yes. And No. You can use it "standalone" too, and we often do so; to develop a whole lot of functions for web use in PHP, then duplicates in some other language, would be frankly silly after all.
And so it is that during the current course, I've been running rather more demos ...
|1194||Drawing hands on a clock face - PHP|
Would you like to draw clock face hands on to an image (such as the one shown here, with the time in UK when you called the page up!)? It's easier than you think using PHP's GD module.
Instead of supplying a fixed image in your <img> tag, provide the URL of a PHP script that reads an image and ...
|1053||Sorting people by name in PHP|
Our petition for a reasonable train service is going great guns - over 1000 signed up in just over a week, amongst them significant players such as MPs, MEPs .... but, my goodness, the list as presented by the web site is hard to look through. So I've grabbed a copy of the list and sorted it - see here.
|1020||Parallel processing in PHP|
PHP is designed - where necessary to the exclusion of other uses - as a web page tool. In other words, where a language design decision needs to made between something that is good for the web use, but bad for more general use, the decision will always be in favour of the web. "I don't care how it effects ...
|917||Syntax checking in PHP|
If you want to check the syntax of your PHP page without actually running it, the -l option (that's lower case letter L) to PHP at the command line will do that for you:
wellho@lightning:~/public_html$ php -l index.php
No syntax errors detected in index.html
|839||Reporting on the 10 largest files or 10 top scores|
What are the biggest 10 files in or below this directory?
What are the 20 'worst' spams I have received in the last month?
What are the five top scores recorded for a popular game on my web site?
It's a very common requirement indeed to provide a program to answer questions like these, and if you've ...
|822||PHP - a team member leaves|
I read that Jani Taskinen, one of (quite a number) of lead developers on the PHP project, has quit after six years. Much PHP development takes place in Israel, and Jani - who has been a UN peacekeeper and who has friends in the Middle East conflicts, concluded that he could not continue to work with ...
|563||Merging pictures using PHP and GD|
I wanted, regrettably, to fade (tear) one picture into another - a train at Melksham into a picture of a disused railway trackbed. We have one of those nearby at Seend, where the Trowbridge - Devizes - Reading - London train service used to run. Here's another 2 options I looked at:
|665||PHP Image viewing application|
PHP has some marvellous facilities for image handling, and I've incorporated some of them into a new thumbnail-viewing demonstration that takes you around many of the images used on our Wiki pages.
The source code of the thumbnail viewer is also available, and you're very welcome to make use of it ... ...
Variable declaration and typing.
Sorting an associative array.
Other array re-ordering functions.
Flexibility with multi-dimensional arrays.
Using PHP to add a counter to an HTML page.
A graphic example.
Using PHP away from the Web Server.
How to use PHP away from the Web Server.
Example of PHP running from keyboard to screen.
What is XML?.
XML handling in PHP.
A Simple Parser.
Extending the example.
Analysing XML as a stand-alone program.
Other XML Subjects.
What is XSLT?.
Handling XSLT in PHP.
If you are looking for a complete course and not just a information on a single subject, visit our Listing and schedule
Well House Consultants specialise in training courses in
. We run
throughout the UK (and beyond for longer courses), and
at our training centre in Melksham, Wiltshire, England.
It's surprisingly cost effective to come on our public courses -
even if you live in a different
country or continent to us
We have a technical library of over 700 books on the subjects on which we teach.
These books are available for reference at our training centre.