You are seeing this very light version of the page, as you are using an outdated browser!

Onlinetools.org is done in XHTML 1.0 and supports CSS 2.0, please upgrade your browser if you want a better version of this site.

Thank you, please help us developers keep up with the industry rather than patching our code for outdated applications.

open or close right navigation

How to create editable web sites in PHP

 
written by:Christian Heilmann on 26.04.2002
Jump to page: 1  2  3  4  5  6  or read all on one page
 

What the script does


1    $filelocation = "mytext.txt";
2    if (!file_exists($filelocation)) {
3    echo "Couldn't find datafile, please contact administrator!";
4    }
5    else {
6    $newfile = fopen($filelocation,"r");
7    $content = fread($newfile, filesize($filelocation));
8    fclose($newfile);
9    }
10    $content = stripslashes($content);
11    $content = htmlentities($content);
12    $content = nl2br($content);
13    echo $content;

Line 1 defines the name of the text file, in line 2-4 the script checks if the file is there and displays a message, when there is no datafile.

If there is a datafile, then the lines 6-8 read it's content into the variable $content.

Lines 10-12 manipulate the content, the backlslashes php adds to quotationsmarks are removed, umlauts and special characters are replaced by their html equivalent and every linebreak becomes a <br />.

Now, we're halfway there, we only need to add the tool that changes the content of the textfile.

more»
Table of contents:

Introduction, what is this about?
Separation is necessary
The template with the script
What the script does
Adding secured interactivity
Goodies and limits

Back to top

Powered by EasyCMS