Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
Extracting data / complex text file format
PHP Revision example from a Well House Consultants training course
More on PHP Revision [link]

This example is described in the following article(s):
   • Extracting real data from an exported file in PHP or Perl - [link]

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

This example references the following resources:
http://www.wellho.net/downloads/melkshammap.pdf

Source code: nibs.php Module: H300
<?php

/* This is a straightforward PHP script that extracts data from
a block of text and reformats it.  The data provided is something
of a mess, in that it's an exported file from a graphic are
program, but never the less it contains all the pertinant data and
we can extract what we need! */

$info = <<<DONE
 Food, Drink, Accommodation
Restaurant, Café (*also takeaway)
Art House Café H       100
Ashers Café    C       101
Cornerstone Café       k       102
Hungry Jacks    Avonside
Lee's Chinese*          103
Lee's Palace* (also delivers)   B       104
McDonald's*             105
Melksham Tandoori *     c       106
Refa Tandoori * k       107
Square Café    b       108
Subway*         109
Sultan, The*    B       110
Waney Edge Café        Berryfield
Takeaway (*delivers)
Acropolis*      c       120
Baguette Bar    C       121
Chick-O-Land    h       122
Chicken Hut*    b       123
Cinnamon*       C       125
Fisheries, The  b       126
Forest Fish Bar Forest
Golden Falls Chinese Takeaway*  k       128
Happy Valley Fish & Chips       Bowerhill
Kebab House*    b       129
King's Gourmet* k       130
Lee's Fish & Chips              131
Peking Chef*    b       132
Pub, Nightclub (*with accommodation)
Bear, The       B       140
Bud's Bar       B       141
Forester's Arms Forest
Grapes, The     B       142
Kings Arms*     H       143
New Inn Berryfield
Parson's Nose, The      C       148
Pig & Whistle, The      Forest
Pilot, The      Bowerhill
Tavern, The     H       145
Unicorn, The            146
West End Inn            147
Accommodation (*with restaurant)
Antonia House   Berryfield
Bowden House            165
Beechfield House*               164
Conigre Hotel & Restaurant*             161
Long Hope Guest House           166
Spa B&B, The            167
Well House Manor                163
Grocery, Bakery, Butcher (*with café)
Aldi            170
Co-op   Queensway & Forest
I. D. Newman Butchers   c       172
Iceland C       173
Jones Convenience Stores        Forest
Jones Day & Night               180
Lidl            174
Lovejoys Foodstore      B       175
Old Bakery, The*        C       176
One Stop        Bowerhill
Premier Post Office & Store     Bowerhill
S K Fruits      C       177
Sainsburys      B       178
Somerfield      b       179
Petrol Station (*open 24 hours)
BP              190
Bonjour/Total*          194
Edwards Garages         191
Stop & Shop/Murco       Forest
Spar Texaco             193
 General Retail and Fashion
Department Store
Original Factory Shop, The      k       200
Leekes          201
Car Sales/Hire
Audi VW Cars    Bowerhill
Auto Tech Motor Engineers               204
Keith Lye       Bowerhill
Mitsubishi Motors               205
Semington Cars of Melksham              206
TJ Self Private HIre            207
Victoria Motors         208
Antiques
Alan & Iris Jaffray Antiques    H       210
Dan Antiques    Avonside
King Street Curios      k       211
Polly's Parlour k       212
Gifts, Toys
Gifts Galore    c       223
Samovar Gift Shop       k       224
Toy Shop, The   b       225
Furnishings
Bedland Bowerhill
First Choice Beds       Avonside
HPS Lounge Suites               226
Electronics and Appliances
Amber Home Appliance Centre     c       230
Apollo Light & Sound    Avonside
BHCS Computer Services  b       233
Compu Hut       b       231
Lighting Superstore     Avonside
Melksham Gas & Electrical       k       232
Melksham Satellites     Avonside
Clothing, Shoes, Accessories
Baby World      Berryfield
Cobblers Bench Shoe Repair      B       240
Helen Passmore  h       242
Inspired        h       246
Marjo Fashions  B       243
Peacocks        b       244
Upper Cut Clothing      C       241
West Country Jewellers  h       245
Charity Shop
Cats Action Trust       B       250
Dorothy House   c       251
Sue Ryder       h       252
Tenovus b       253
Stationer, Newsagent, Tobacconist
Business2Exchange       Bowerhill
Card and News Centre    B       260
Castles Newsagents      k       261
Clinton Cards   C       262
D.A.C. Stationery       b       263
Newsbox C       264
Bath Road Store         265
Decorating, Interiors, DIY
Artisan Hire Centre     Bowerhill
Buildbase       Bowerhill
Carpet Barn     b       270
County Glass and Glazing        Avonside
County Tile Warehouse   Avonside
Falcon Interiors                273
Melksham Kitchen & Appliance    B       274
Pearces of Melksham     c       275
Pine Plus               278
Plumbstop               277
Tile & Bathroom Centre  B       276
Universal Tool Hire     Bowerhill
Garden, Florists
Flower Care     C       280
Flowers in Focus        b       281
Greenlands Fencing & Patio Ctr          282
Timber Track Sheds              283
Other
K. M. Military  k       290
Marks Musical Instruments       B       291
Pound World     C       292
Sewing Basket   c       293
What the Dickens Bookshop       c       294
 Professional Services
Banks, Finance and Insurance
Barclays        b       300
Baron Martin    C       306
Halifax h       301
Heywoods Insurance      c       309
Heywoods Commercial Ins c       310
HSBC    C       302
IMI General Insurance Services  B       311
Lloyds TSB      h       303
Mortgage Advice Bureau  H       307
Nationwide      C       308
NatWest B       304
Stroud & Swindon        C       305
Estate Agent
CS Property     K       326
Hames & Joy     B       320
Jayson Kent     H       322
Kavanaghs       C       323
Kingstons       h       324
Lock & Key Ind Estate Agents    C       325
Employment
Bailey Employment Services      K       330
Staffwise Recruitment   H       331
West Country Educational Agy    C       332
Photography
Andy York Photography   b       340
BC Photographic c       341
Funeral Directors
D. J. Bewley    b       350
H. Merrett Funeral Directors    c       351
Other Services
Forest Laundrette       Forest
In Tune Music School    C       362
Lock It Shop    b       360
Melksham Independant News       H       367
South of Heaven Tattoo  c       363
Thomas Cook Travel      C       364
Tourist Information Centre      c       365
West County Cleaners    C       366
 Health & Beauty
Personal Healthcare (*has pharmacy)
Anthony Day Dental Surgery      K       407
Boots*  C       400
Chinese Medical Centre  h       401
Giffords P.C.C.*                405
Gompels*        b       402
Market Place Dental Practice    H       408
Regency Dental Practice K       409
St. Damian's Surgery*           406
Spa Medical Centre*             404
Superdrug       B       403
Opticians
Buy Specs Direct        B       410
Haine and Smith C       411
Nixon and Shaw  h       412
SpecSavers      b       413
Salon, Barber Shop, Spa
Barber Shop, The        b       420
Shavers c       421
Clarkies        B       422
G. Hatto        K       423
Glow    K       424
Hairtek b       425
Just Beauty Plus        b       426
Just for Men Unisex     k       427
Just Nails/Sunseekers Tanning   B       428
Libra Hair Salon        B       429
M & H Hair Studio       B       430
Robert Michaels Hair Team       B       431
Scissors        Forest
Studio Two      c       432
Tops Hair Salon h       433
Works, The      b       434
Pets
Beeches Veterinary Centre               504
Church Lane Veterinary Srgy     Forest
Countrywide             510
Critters        H       501
Hale Veterinary Group   B       502
Petstown        B       500
Rainbow Koi     Avonside
Exotic Pet Centre, The  C       503
 Leisure
Entertainment
Blockbuster     k       600
Gaming Galore   b       601
Fitness
Curves Gym      Avonside
Fitness First Gym       Avonside
Scott's Gym     Avonside
Sporting Goods
Avon Angling & Sports   b       613
Bob Missen Bike Shop    h       610
DJ's Sports Shop        b       611
Melksham Cycles Centre          612
Tackle Shop     Avonside
Sport, Leisure/Social Centre
Boomerang       Bowerhill
Christie Miller Sports Centre   Bowerhill
Diving Zone     Avonside
Melksham Blue Pool      H       620
Wilts School of Gymnastics      Bowerhill
Betting
Backhouse Bet   K       630
Regency Amusements      C       631
William Hill    b       632
DONE;

// ---------------- go through the data line by line

$records explode("\n",$info);
$err 0;
foreach (
$records as $record) {
        
// get rid of trailing tabs
        
$tdr trim($record);
        
// change accent characters
        
$tdr preg_replace('/./','&eacute;',$tdr);
        
$els explode("\t",$tdr);

        
// Look at each line in turn

        
if (ereg("^ ",$record)) {  # MAIN HEADER
                
$html .= "<tr><td colspan=3><h2><br>$tdr</h2></td></tr>\n";
                }
        elseif (
count($els) == 1) {  # SUB HEAD
                
$html .= "<tr><td colspan=3><h4><br>$tdr</h4></td></tr>\n";
                }
        elseif (
count($els) == and ereg("^[1-9]",$els[1])) {
                                
# OUT OF TOWN LOCATION on map
                
$html .= "<tr><td>$els[0]</td>";
                
$html .= "<td colspan=2>$els[1]</td></tr>\n";
                }
        elseif (
count($els) == 2) {  # OUT OF TOWN LOCATION not on map
                
$html .= "<tr><td>$els[0]</td>";
                
$html .= "<td colspan=2>at $els[1]</td></tr>\n";
                }
        elseif (
count($els) == 3) {  # IN TOWN LOCATION
                
$zone strtoupper($els[1]);
                
$html .= "<tr><td>$els[0]</td>";
                
$html .= "<td>$zone</td>";
                
$html .= "<td>$els[2]</td></tr>\n";
                }
        else {  
# ERROR
                
$html .= "<tr><td colspan=3>******</td></tr>\n";
                
$err 1;
        }
}
// ----------------------------------------------------------
?>
<html>
<head>
<title>Melksham Businesses - from Retail Business Map</title>
<body>
This is a list of Melksham businesses who are open for customers and can
usually be visited without an appointment.<br><br>
The locations shown are on the
<a href=http://www.wellho.net/downloads/melkshammap.pdf>Melksham
Town Map</a>.<hr>
<table cellpadding=2 cellspacing=2>
<?= $html ?>
</table><br>
Produced by Well House Consultants.
</body>
</html>

Learn about this subject
This module and example are covered on the following public courses:
 * PHP Techniques
 * Intermediate PHP - weekend course / hobby / club / leisure users
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 "PHP Revision" training module. You'll find a description of the topic and some other closely related examples on the "PHP Revision" 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.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2021: 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