Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
For 2023 - 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))

Posted by TedH (TedH), 15 January 2006
I can create, read and edit text files fine.

The next step is to do that with part of an HTML file.

Suppose I have an HTML file:

<table><tr><td>The Header</td></tr></table>


<table><tr><td>The Footer</td></tr></table>

I know I have to open the file, read into an array, close, open again and do something with it.

How do I just print the word 'Hello' to the screen and not the rest of the code?

I figure if I can print it to screen I can get it into an editing form to edit the text on the HTML page.

I think I'm approaching this the right way ...

- Ted

Posted by admin (Graham Ellis), 15 January 2006
It might be worthwhile for you to explain a little bit more about what you're doing; the obvious answer if you want to see just the text and not the HTML on the screen is you say "view ith through a browser rather than a terminal window" but I don't think that's quite what you intend.

Are you by any chance putting together a web site where you edit th epage content through the browser - a content management system / wiki?

We've a system that you can read about and experiment with if you like.  In practise, it's better to use an alternative markup system such as BBS as that avoid users putting "nasties" into the page, and also to keep the page look-and-feel separate from the actual data.  So, in practise, it rather avoids the question you were originally asking  

Posted by TedH (TedH), 15 January 2006
Hi Graham, looked at your 'Sandbox' idea. In a way I suppose it would be similar to the edit screen (but it's inside an admin area).

What I have is a CMS for my site that I've written and it uses text files and SSIs. Works okay, just thought I'd like to edit the actual page instead of a text file. It's the use of the two tags that throws me on this.

HTML file is created from a template with bits like page title etc. At one point I have my include and the file for it is edited in the CMS (include and file would be replaced by 2 tags with text). Outsiders would not edit it like the Sandbox, only myself.


use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
print "Content-type: text/html\n\n";
$thefile = "test.html";

# Open file read it in and close it
open(THF, $fileview) || die("could not open");

# Open again and print file with linebreaks.
open (THF, "$fileview") || die ("Could not open file!");
$mydata = <THF>;

while (<>) {
   if (/\<\!--aa--\>/ .. /\<\!--eaa--\>/) {
       # The two periods are the entire text
       # between the tags (in this case 'Hello').
   print "$mydata"; # this does not work
       # Not sure what to put here?
close (THF);

Am I making sense of this or approaching it from the wrong direction?

Posted by admin (Graham Ellis), 15 January 2006
Hmm .. I think you're (as you ask) putting it in the wrong direction.   But I'm having lots of thoughts here and want to say hundreds (exaduration) things all at the same time.

A) GOLDEN RULE when designing any sort of content management system - keep the data (i.e. the content) in a different place to the look and feel (HTML / CSS) of the page.  


1. You can easily edit content without having to get mixed up with the look and feel it's embedded in

2. You can easily change the look and feel without having to mess with content

3. You can use one look and feel for multiple pieces of content and even vice versa if you wish.

B) Our WIKI isn't all public I pointed you at a publicly editable page - i.e. a page a guest can change.  99% of the pages there can only be changed by someone who's logged in ... things like our diary are all a part of the same system - it's just that only Lisa, Leah and I can login to make changes.  The same scheme and code works for public and private pages and the system contains some pages that are so private that you can't even read them without logging in. [i]By the way ... Wikis are quite common and it's not the big problem you think to allow public changes.  On busy systems, the responsible people soom police the rogues, and on our quieter system any guest changes get emailed to us so we can quickly deal with issues.

C) HOW TO do it - best practise.  Keep the template (look and feel) of the pages in one file - HTML with a marker whihc could be the one you're already using.   Keep the edited data in a second file (or series of files, or database) and merge the pages at run time.

If you want your pages to have a nice URL when really they're all the same perl script, use mod_rewrite.

I'm getting a bit long and "preachy" here - that's an occupational hazard with CMS!   You've see the Wiki.   If you look at our home page and see the news there, that's another form we use in the same way, and another (the simplest, and I think similar to what you need) piece of CMS.   If you want it (in PHP!) I can post some source as to how we include and edit it.  Then this forum is a type of CMS, and so is my blog.  Big topic ...

Posted by TedH (TedH), 15 January 2006
Cheers Graham, That's great advice. I've never used mod_rewrite before so will check that out.

I had wanted to have HTML pages so they'd get picked up by the search engines better and wasn't sure if SSIs calling each file to each page actually worked (doesn't seem to anyway).

Currently I create a new html page with all the SSIs and that written in and the text file is also created then stored in a folder on the website (

So this all oughta keep me busy for a bit...

thanks muchly - Ted

Posted by admin (Graham Ellis), 16 January 2006
If the user calls up a page with a ".html" extension and gets fed HTML, how's he to know what's going on internally?  

Most Content Management Systems use some form of URL redirection or rewriting ... many, many pages on our web site do it and get indexed very well.

Have a look at and follow some of the links to other places.   All different pages?  No - not exactly; all the same script but the .htaccess file in the share directory includes

RewriteEngine On
RewriteRule ^(.*)\.html /share/index.php4?pagename=$1
RewriteRule ^(.*)\.upd /share/index.php4?pagename=$1&edit=1

Posted by TedH (TedH), 17 January 2006
Did a quick look at mod_rewrite and realised this is not a quick look thing. Wow.... looks like I'll have to spend some time on checking it out.

cheers - ted

This page is a thread posted to the opentalk forum at and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2023: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: • WEB: • SKYPE: wellho