RE [thelist] Simple page editor

BJ bj at kickasswebdesign.com
Wed Mar 16 18:51:21 CST 2005


"I am looking for a simple script (PHP preferred) that will change a 
single page on a site."

A friend made a script like this for me-- it very simply inserts the contents of a .txt file (script currently set for it to be named "includeme.txt")  within the page where you specify.  The person who updates that file would need to know some simple html formatting-- headlines and the strong tag will probably be sufficient.  If the page is xhtml they'll need to use p tags within the txt file, and you'll need to get rid of that part of the php snippet that writes the initial p tag since xhtml requires closed tags to validate.  Anyway, once the script is in place they'd simply have to upload the new file and overwrite the old for the page to be updated.  Simply include this code within an html page, and save the page with the extension php.  Then upload the txt file to the same directory.  There may be fancier ways to do this, but I can't tell you how many times I've used this script!  Clients use it for updating calendars, menus, recipes, schedules, etc. and they and I are all happy they don't have to call me for little chores like this! I have put the html and txt pages into their own directory just to keep the murphy factor to a minimum since most of these folks are just barely computer literate, and have to be taught how to ftp-- I usually set the ftp up for them if they're local to me and set it to point directly into that directory.  

Here's the code:

    <!-- PHP snippet begins here. c. Mark Finnegan, http://uninspireddomainname.com. Copy from here. -->
    <!-- PHP Fragment to read in a text file and add it to the page in question.  -->
    <!-- It needs to translate carriage returns (either unix or windows) to <P> tags (Or other text as defined by setup). -->
    <!-- Needs to check for existence of file first, then display either file contents or placeholder text. -->
    <!-- PHP Variable assignments -->
    <?php
$newline = "<P>";
$filename = "includeme.txt";
$placeholder = "No updates available today.";
?>
    <!-- End PHP Variable assignments -->
    <!-- Check file exists. Read it in if it does. Otherwise read in the placeholder value. -->
    <?php
echo ($newline);
if (file_exists ($filename))
{
   $the_text = file($filename);
}
else
{
   $the_text[0] = $placeholder;
}
?>
    <!-- Write out the file text, replacing the newlines with the newline tag or text.-->
    <?php
$the_text = array_reverse($the_text);
while ($the_text)
{
   echo (substr(array_pop($the_text), 0,-1));
   echo ($newline);
}
?>
    <!-- PHP snippet Ends here. Copy to here. -->





More information about the thelist mailing list