Exercises, examples and other material relating to training module H109. This topic is presented on public courses
Learning to program in PHP,
PHP Programming
Between accesses to your web pages, data will be stored in data files or in SQL databases. There will also be many applications where initial data is provided in files, or web applications are used to add content to files or make amendments.
| Articles and tips on this subject | updated |
| 3424 | Divide 10000 by 17. Do you get 588.235294117647, 588.24 or 588? - Ruby and PHP If you divide £10,000 between 17 lucky children, each gets £588.23 ... but if you divide the number 10,000 by the number 17, you get 588.235294117647. How do you format the data to the appropriate number of decimal places?
In Ruby, you can use the % operator on a string - which is an alias ... | 2011-09-08 |
| 3159 | Returning multiple values from a function call in various languages - a comparison I've always thought it a bit odd that you call a function with any number of parameters, and yet it returns a single value; in Java, C or C++ you declare a return type (void if there is not to be anything returned) and you are then constrained by that specification. There are, of course, other ways ... | 2011-02-10 |
| 3029 | PHP data sources - other web servers, large data flows, and the client (browser) As always, I've written a sprinkling of new demonstrations amongst some well-trodden example during the PHP course I'm presenting this week:
There's a really short example of how you can call up another server from your own server - [here]. So much more can be made of the web by presenting and combining ... | 2010-11-04 |
| 2964 | An introduction to file handling in programs - buffering, standard in and out, and file handles Stdout and Stderr
Programmers typically don't write code to output to the screen / current window, as to to so would be to provide an inflexible system - instead, they output to what's known as "standard out", also known as stdout. Usually stdout defaults to the screen / current window so there's no ... | 2010-09-21 (longer) |
| 1780 | Server overloading - turns out to be feof in PHP From the manual page on feof:
Warning - If passed file pointer is not valid you may get an infinite loop, because EOF fails to return TRUE.
From a script on our server:
while (1) {
$nlines ++;
$line = fgets($fh,1024);
if (feof($fh)) break;
OOps! ... the file that's ... | 2008-09-01 |
| 1442 | Reading a file multiple times - file pointers When you open a file for read, you create a "file pointer" which knows where in the file you are, and each time you read from the file this advances so that you get the next piece of data each time you do a read. Usually you don't see the file pointer at all - it's internal - and you think nothing ... | 2007-11-27 |
| 1113 | File and URL reading in PHP In PHP, we say "there's a function to do that" as the answer to almost any question is going to be in the form of a function name, or a list of functions, to call. And PHP has more functions than almost any other language, making it more flexible than most.
Take file handling ... where in so many ... | 2007-03-21 |
| 1096 | Sample script - FTP to get a file from within PHP A worked example from today's course - Only the password has been changed
<?php
$conn_id = ftp_connect("www.savethetrain.org.uk");
$login_result = ftp_login($conn_id, "savethetrain", "melksham");
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
exit;
} else ... | 2007-03-01 |
| 1094 | PHP fread - truncated data Note that PHP's fread function returns the number of bytes you request as the second parameter ...OR the number of remaining bytes if it's less than the number you give ... or 8192 bytes, even if there's more than that available and you've requested more.
I got caught out by this one earlier today ... ... | 2007-02-28 (short) |
| 997 | Most recent file in a directory - PHP Want to report the most recently updated file in a directory in PHP? It's the sort of thing we all want to do, but in a variety of modified forms, quite often ... here's a code snippet to do it for you:
$dir = "/home/wellho/public_html/demo";
$pattern = '\.(html|php|php4)$';
$newstamp = 0;
$newname ... | 2006-12-21 |
| 653 | Easy feed! Want to provide sites that work close along side you with a feed of your blog? In recent versions of PHP, you can include a remote file from their server in your page. Here's a little example that's on our site - we're pulling down a piece of PHP via a URL.
Want the latest news from Well House Consultants? ... | 2006-06-05 |
| 709 | Handling huge data files in PHP I've handled files up to 2 GBytes in size with PHP ... but there are a number of issues to consider.
1. The size of the PHP "footprint" in memory - when you have a huge data file, you cannot simply read it all in with file or file_get_contents (nor with fread, trying to read the file all at once). Rather, ... | 2006-05-04 |
Examples from our training material
Pictures
PHP Programming course
Background information
Some modules are
available for download as a sample of our material or under an
Open Training Notes License for free download from
http://www.training-notes.co.uk.
Topics covered in this module
Input from a file.
Checking a file and looking around.
Example of output to a file.
Complete learning
If you are looking for a complete course and not just a information on a single subject, visit our
Listing and schedule page.
Well House Consultants specialise in training courses in
Python,
Perl,
PHP, and
MySQL. We run
Private Courses throughout the UK (and beyond for longer courses), and
Public Courses 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. Also
available is the Opentalk
Forum for discussion of technical questions.