Training, Open Source Programming Languages

This is page http://www.wellho.net/resources/ex.php4

Our email: info@wellho.net • Phone: 01144 1225 708225

 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Using PHP to format data (timetable in this example)
String Handling in PHP example from a Well House Consultants training course
More on String Handling in PHP [link]

This example is described in the following article(s):
   • Here documents - [link]

If you're searching for a page where you can try this code, select here

Source code: bustimes.php Module: H107
<?php

# Using PHP to format data (timetable in this example)

# Here is the raw data ... (usually read from a file?)

$datasource = <<<BUSDATA
<h2>X72 (with 272, X71, X85, X86 and X76) Bus - Bath to Devizes</h2>
<b>Monday to Saturday</b>

* <a_href=/share/bath.html>Bath</a> <a_href=/share/melksham.html>Melksham</a> <a_href=http://www.wellhousemanor.co.uk>Well_House_Manor<a> Sells_Green <a_href=/share/devizes.html>Devizes</a>
06:45 07:21 07:23 07:33 07:43 NS
07:40 08:15 08:17 08:27 08:41 NS
07:55 08:32 ----- ----- ----- FS,NS,X85
09:00 09:38 09:40 09:50 10:00
10:00 10:39 10:41 ----- ----- NS,FS
10:02 10:38 10:40 10:50 11:00
11:00 11:39 11:41 ----- ----- NS,FS
11:02 11:38 11:40 11:50 12:00
12:00 12:39 12:41 ----- ----- NS,FS
12:02 12:38 12:40 12:50 13:00
13:00 13:40 13:42 13:54 14:00 NS,FS
13:02 13:38 13:40 13:50 14:00
13:40 14:15 ----- ----- ----- X76,ADR
14:00 14:40 14:42 ----- ----- NS,FS
14:15 15:12 ----- ----- ----- SO,FS,X86
14:20 14:55 ----- ----- ----- NS,FS
14:32 15:08 15:10 15:20 15:30
15:32 16:11 16:13 16:23 16:33
16:30 17:03 17:05 ----- ----- NS,FS
16:32 17:08 17:10 17:20 17:30
17:30 18:03 18:05 ----- ----- NS,FS
17:30 18:15 ----- ----- ----- NS,FS,X86
17:45 18:20 -(a)- 18:40 18:50
18:20 18:54 -(a)- 19:12 19:22
20:20 20:54 20:56 21:06 21:16
23:00 23:34 -(a)- 23:45 23:56

NS - Not Saturday
SO - Saturday Only
ADR - ADRains service
FS - Operated by Faresaver, route 272. All other services operated by First.
-(a)- - Service X71, not via Well House Manor. Join or alight at Melksham Town Centre
X86 - Route X86 via Bradford-on-Avon (Saturday)
X85 - via Bradford-on-Avon
X76 - Bath to Marlborough via Melksham

Tickets are NOT interchangable between Faresaver and First

<b>Sunday and Bank Holidays</b>

* Bath Melksham Well_House_Manor Sells_Green Devizes
10:30 11:02 11:04 11:14 11:22
12:30 13:02 13:04 13:14 13:22
14:30 15:02 15:04 15:14 15:22
16:30 17:02 17:04 17:14 17:22
18:30 19:02 19:04 19:14 19:22
19:30 20:02 20:04 20:14 20:22

<h2>X72 (with X71) - Devizes to Bath</h2>
<b>Monday to Saturday</b>

* Devizes Sells_Green Well_House_Manor Melksham Bath
----- ----- -(b)- 07:00 07:33 NS
----- ----- ----- 07:05 07:54 NS,FS,X86
----- ----- -(b)- 07:30 08:08 NS
07:19 07:29 07:37 07:42 08:21
----- ----- 09:10 09:14 09:58 NS,FS
09:00 09:10 09:18 09:23 09:57
----- ----- ----- 09:50 10:50 SO,FS,X86
----- ----- ----- 10:01 10:40 X76,ADR
----- ----- 10:10 10:14 10:58 NS,FS
10:00 10:10 10:18 10:23 11:02
----- ----- 11:10 11:14 11:58 NS,FS
11:00 11:10 11:18 11:23 11:57
----- ----- 12:10 12:14 12:58 NS,FS
12:00 12:10 12:18 12:23 13:02
----- ----- 13:10 13:14 13:58 NS,FS
13:00 13:10 13:18 13:23 13:57
14:03 14:14 14:22 14:27 15:01
15:00 15:10 15:18 15:23 15:57
15:40 15:46 15:52 15:56 16:28 NS,FS
----- ----- ----- 16:50 17:27 NS,FS,X85
----- ----- ----- 16:56 17:28 NS,FS
16:35 16:45 16:53 17:00 17:34
17:40 17:49 17:57 18:02 18:35 NS
18:25 18:34 -(b)- 18:52 19:25
19:25 19:34 19:42 19:46 20:18
22:02 22:10 22:18 22:22 22:55

NS - Not Saturday
SO - Saturday Only
ADR - Operated by ADRains
X86 - Route X86 via Bradford-on-Avon (Saturday), operated by Faresaver
X85 - via Bradford-on-Avon, operated by Faresaver
FS - Operated by Faresaver, route 272. All other services operated by First.
-(b)- - Service X71, not via Well House Manor. Join or alight at Melksham Town Centre
X76 - From Lowborne in Melksham (through bus from Marlborough)

Tickets are NOT interchangable between Faresaver and First

<b>Sunday and Bank Holidays</b>

* Devizes Sells_Green Well_House_Manor Melksham Bath
10:12 10:18 10:27 10:32 11:02
12:12 12:18 12:27 12:32 13:02
14:12 14:18 14:27 14:32 15:02
16:12 16:18 16:27 16:32 17:02
18:12 18:18 18:27 18:32 19:02
20:02 20:08 20:17 20:22 20:52
21:02 21:08 21:17 21:22 21:52

NOTE - Times at Well House Manor are ESTIMATED and you should be at bus stop a few minutes early.

<h2>234 (with Train, X34, X96, 73, 235 and 237) Bus/Train - Trowbridge to <a href=/share/chippenham.html>Chippenham</a></h2>
<b>Monday to Saturday</b>

* <a_href=/share/frome.html>Frome</a> <a_href=/share/trowbridge.html>Trowbridge</a> Melksham <a_href=/share/lacock.html>Lacock</a> Chippenham_Railway_Station Chippenham_Bus_Station
----- 07:08 07:17 ----- 07:30 ----- Train,NS
----- 07:01 07:21 07:30 07:39 07:43
07:00 ----- 07:45 ----- ----- ----- FM
07:05 07:25 07:40 ----- ----- ----- FS,NS
----- 07:40 08:07 08:34 08:50 08:55 SD
----- 07:50 08:13 08:23 08:39 08:44 NSD
----- ----- 08k21 08:31 08m42 08:55 FS,NS
----- ----- 08:35 08:48 ----- ----- FS,SO,73
----- 08:25 08:55 ----- ----- ----- 237
----- 09:01 09:18 ----- ----- 09:45 FS,NS
----- 09:13 09:22 ----- 09:32 ----- Train,SO
----- 09:02 09:25 09:35 09:51 09:56
09:33 10:01 10:18 ----- -(c)- 10:45 FS,NS
09:36 10:05 10:28 10:38 -(c)- 10:53
----- 10:05 10:35 ----- ----- ----- 237
----- ----- 10:35 10:48 ----- ----- FS,NS,73
10:33 11:01 11:18 ----- -(c)- 11:45 FS,NS
10:36 11:05 11:28 11:38 -(c)- 11:53
----- 11:20 11:50 ----- ----- ----- 237
11:33 12:01 12:18 ----- -(c)- 12:45 FS,NS
11:36 12:05 12:28 12:38 -(c)- 12:53
----- 12:40 13:10 ----- ----- ----- 237
12:33 13:01 13:18 ----- -(c)- 13:45 FS,NS
12:36 13:05 13:28 13:38 -(c)- 13:53
----- ----- 13w40 13:55 ----- ----- FS,NS,73
----- 14:00 14:30 ----- ----- ----- 237
13:33 14:01 14:18 ----- -(c)- 14:45 FS,NS
13:36 14:05 14:28 14:38 -(c)- 14:53
14:14 14:36 14:50 ----- ----- ----- FS,NS
----- 15:09 15:19 ----- 15:28 ----- Train,SO
14:36 15:05 15:28 15:38 -(c)- 15:53
----- 15:20 15:50 ----- ----- ----- 237
----- ----- 15:50 16:11 ----- ----- FS,SO,73
15:14 15:50 16:06 ----- -(c)- 16:27 FS,NS
15:56 16:25 16:48 16:58 -(c)- 17:13
----- 16:50 17:20 ----- ----- ----- 237
----- 17:14 17:34 ----- -(c)- 17:52 FS,NS
----- 17:20 17:45 ----- ----- ----- 235,NS
17:08 17:40 17:57 ----- -(c)- 18:14 FS,NS
17:12 17:41 18:04 18:14 -(c)- 18:26
----- 18:35 18:53 19:02 -(c)- 19:13
----- 19:41 19:51 ----- 20:01 ----- Train,NS
----- 20:00 20:18 20:27 -(c)- 20:38
----- 21:25 21:43 21:52 -(c)- 22:03
----- 23:11 23:29 ----- ----- -----

FM - Frome Minibuses service via Bradford-on-Avon
FS - Faresaver service X34 or 73. All others are First service 234
NS - Not Saturdays
SO - Saturday Only
SD - School Days Only
NSD - All Saturdays, Monday to Friday during school holidays
k - also calls at Well House Manor at 08:17
w - also calls at Well House Manor at 13:38
m - Wiltshire College, across road from Railway Station
-(c)- - Does not serve railway station
235 - service 235 also serves Well House Manor
73 - Service 73 via Melksham Forest
237 - Service via Holt

First and Faresaver tickets are NOT interchangeable

<b>Sunday and Bank Holidays</b>

* Frome Trowbridge Melksham Lacock Chippenham_Railway_Station Chippenham_Bus_Station
----- 19:42 19:51 ----- 20:02 ----- Train
----- 21:34 21:44 ----- 22:02 ----- Train

<b>Monday to Saturday</b>

* Chippenham_Bus_Station Chippenham_Railway_station Lacock Melksham Trowbridge Frome
----- 06:35 ----- 06:44 06:54 ----- Train,NS
06:55 -(c)- ----- 07:12 07:30 ----- NS,FS
----- ----- ----- 07:16 07:37 -----
----- ----- ----- 07:43 08:21 ----- 235,NS
----- ----- ----- 07:43 08:27 ----- 237
07:40 -(c)- ----- 08:04 08:27 08:58
07:45 -(c)- 08:01 08:12 08:40 09:18
08:57 -(c)- ----- 09:23 09:40 10:05 NS,FS
----- ----- ----- 09:25 09:55 ----- 237
09:00 -(c)- 09:12 09:23 09:45 10:15
----- ----- 09:22 09:36 ----- ----- SO,FS,73
----- ----- 09:47 10:01 ----- ----- NS,FS,73
09:57 -(c)- ----- 10:23 10:40 11:05 NS,FS
10:00 -(c)- 10:12 10:23 10:45 11:15
----- ----- ----- 10:40 11:10 ----- 237
10:57 -(c)- ----- 11:23 11:40 12:05 NS,FS
11:00 -(c)- 11:12 11:23 11:45 12:15
----- ----- ----- 12:00 12:30 ----- 237
----- ----- 11:47 12:01 ----- ----- NS,FS,73
11:57 -(c)- ----- 12:23 12:40 13:05 NS,FS
12:00 -(c)- 12:12 12:23 12:45 13:15
12:57 -(c)- ----- 13:23 13:40 14:05 NS,FS
13:00 -(c)- 13:12 13:23 13:45 14:15
----- ----- ----- 13:30 14:00 ----- 237
----- ----- 13:23 13:36 ----- ----- SO,FS,73
13:57 -(c)- ----- 14:23 14:40 15:05 NS,FS
14:00 -(c)- 14:12 14:23 14:45 15:15
----- ----- ----- 14:40 15:10 ----- 237
----- ----- ----- 15:38 15:59 16:40 NS,FS
15:10 15:15 15:30 15:43 16:05 16:43
----- 15:35 ----- 15:45 15:55 ----- Train,SO
----- ----- ----- 15:55 16:25 ----- 237
16:30 16:35 16:50 17:01 17:23 17:53
16:30 16m35 ----- 16:57 17:10 ----- NS,FS
17:05 ----- ----- 17:22 17:37 ----- NS,FS
17:25 ----- ----- 17:53 18:11 18:30 NS,FS
17:30 17:35 17:50 18:01 18:23 -----
----- ----- ----- 18:18 ----- 19:03 FM
18:30 18:34 18:46 18:56 19:15 -----
----- 18:58 ----- 19:08 19:18 ----- Train,NS
19:20 19:24 19:34 19:44 20:02 -----
20:40 20:44 20:54 21:04 21:22 -----
----- 21:09 ----- 21:18 21:28 ----- Train,SO
22:06 22:10 22:20 22:30 22:48 -----

FM - Frome Minibuses service X86 via Bradford-on-Avon
FS - Faresaver service X34 or 73. All others are First service 234
NS - Not Saturdays
SO - Saturdays Only
m - Wiltshire College, across road from Railway Station
-(c)- - Does not serve railway station
235 - Service 235 ALSO CALLS at Well House Manor
237 - Service 237 via Holt
73 - Service 73 via Melksham Forest

First and Faresaver tickets are NOT interchangeable

<b>Sunday and Bank Holidays</b>

No Service at all in the Chippenham - Melksham - Trowbridge direction.
BUSDATA;

# Read and format the data into $ht

$intable 0;
$ht "";
$datalist explode("\n",$datasource);
foreach (
$datalist as $line) {
        if (
$intable) {
                
$fol explode(" ",$line);
                if (
count($fol) < 2) {
                        
$intable 0;
                        
$ht .= "</table><br>$line<br>";
                } else {
                        
$ht .= "<tr>";
                        foreach (
$fol as $cell) {
                                
$ht .= "<td align=center>$cell</td>";
                        }
                        for (
$kcount($fol); $k<=$placecount$k++) {
                                
$ht .= "<td>&nbsp;</td>";
                        }
                        
$ht .= "</tr>\n";
                }
        } else {
                if (
ereg('^\*',$line)) {
                        
$intable 1;
                        
$ht .= "<table border=1><tr>";
                        
$fol explode(" ",$line);
                        
array_shift($fol);
                        
$placecount 0;
                        
$pcw floor(100 / (1+count($fol)));
                        foreach (
$fol as $cell) {
                                
$cell preg_replace("/_/"," ",$cell);
                                
$ht .= "<th width=$pcw%>$cell</th>";
                                
$placecount++;
                                }
                        
$ht .= "<td align=center>note</td></tr>\n";
                } else {
                        
$ht.= $line."<br>";
                }
        }
}

# Generate resulting web page

?>
<html>
<head><title>Melksham Bus and Train timetables - Summer 2007</title>
<body>
This page is a combination of all operators and routes bus and train times from Melksham to Bath, Devizes, Chippenham, Trowbridge and Frome for Summer 2007.<br><br>
<b>TOP OF PAGE</b> - Bath - Melksham - Devizes and vice versa<br><br>
<b>LOWER ON PAGE</b> - Frome - Trowbridge - Melksham - Chippenham and Vice Versa<br><br>
<?= $ht ?>
</body>
</html>

Learn about this subject
This module and example are covered on the following public courses:
 * Learning to program in PHP
 * PHP Programming
 * Beginning PHP - weekend course / hobby / club / leisure users
 * PHP Programming
 * Learning to program in PHP
Also available on on site courses for larger groups

Books covering this topic
Yes. We have over 700 books in our library. Books covering PHP are listed here and when you've selected a relevant book we'll link you on to Amazon to order.

Other Examples
This example comes from our "String Handling in PHP" training module. You'll find a description of the topic and some other closely related examples on the "String Handling in PHP" module index page.

Full description of the source code
You can learn more about this example on the training courses listed on this page, on which you'll be given a full set of training notes.

Many other training modules are available for download (for limited use) from our download centre under an Open Training Notes License.

Other resources
• Our Solutions centre provides a number of longer technical articles.
• Our Opentalk forum archive provides a question and answer centre.
The Horse's mouth provides a daily tip or thought.
• Further resources are available via the resources centre.
• All of these resources can be searched through through our search engine
• And there's a global index here.

Purpose of this website
This is a sample program, class demonstration or answer from a training course. It's main purpose is to provide an after-course service to customers who have attended our public private or on site courses, but the examples are made generally available under conditions described below.

Web site author
This web site is written and maintained by Well House Consultants.

Conditions of use
Past attendees on our training courses are welcome to use individual examples in the course of their programming, but must check the examples they use to ensure that they are suitable for their job. Remember that some of our examples show you how not to do things - check in your notes. Well House Consultants take no responsibility for the suitability of these example programs to customer's needs.

This program is copyright Well House Consultants Ltd. You are forbidden from using it for running your own training courses without our prior written permission. See our page on courseware provision for more details.

Any of our images within this code may NOT be reused on a public URL without our prior permission. For Bona Fide personal use, we will often grant you permission provided that you provide a link back. Commercial use on a website will incur a license fee for each image used - details on request.

© WELL HOUSE CONSULTANTS LTD., 2024: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/resources/ex.php4 • PAGE BUILT: Sun Oct 11 14:50:09 2020 • BUILD SYSTEM: JelliaJamb