Using include() and text files to dummy-proof a page - help!

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
outatime257
Forum Newbie
Posts: 2
Joined: Tue Dec 13, 2005 10:24 am

Using include() and text files to dummy-proof a page - help!

Post by outatime257 »

Hey everyone-
I'm trying to figure out a dummy-proof way to alter a PHP file so PHP-illiterate folks can change the content on it. The area in question is on the right side of this page: http://www.protectamericanfamilies.org. (Don't laugh, I hate the design too.)

Anyway, it's done in wordpress, and the right sidebar is really part of index.php. (Don't ask, just smile and nod.) The people who are writing the content on the site don't know any HTML or PHP at all, so I used a PHP include() script and a separate file called action_item.php that they could edit in order to change the content:

<?php include 'action_item.php';?>

<?php echo "$headertext";?>

<?php echo "$descriptiontext";?>

<a href="<?php echo "$actionpagelink";?>">


The action_item.php file is basically a series of variables like $headertext, $description, etc. that they can edit in the Wordpress dashboard... like so:

/*Title of current action item goes between single quotes*/
$headertext = 'La la la';

/*Place description text of current action between single quotes*/
$descriptiontext= 'blah blah blah';

and so on.

I very pointedly told them to put their text between the single quotes, add a backslash before any apostrophes, etc. Yet they still keep on screwing up the site by forgetting to close the quotes, forgetting to put a backslash before apostrophes, or directly dumping text from Word (so smart quotes show up, which means if they actually remember to do the backslash, the backslash itself shows up along with the smart quote). Go figure.

Anyway, I'm trying to figure out an even more foolproof way for them to change the right side text. Basically, there will be 3 text files - each one will have the corresponding header, description, and link - and then somehow get those text files in as variables into another file.

Would I still use an include() function, or will that not work if they're .txt files? I'm certainly no expert at PHP, so any advice is needed.
choppsta
Forum Contributor
Posts: 114
Joined: Thu Jul 03, 2003 11:11 am

Post by choppsta »

Rather than using include() you could use:

Code: Select all

$string = file_get_contents($fileName);
This will get the content of the file $fileName and put it in $string.
You can then split the text out or do what ever to it.
outatime257
Forum Newbie
Posts: 2
Joined: Tue Dec 13, 2005 10:24 am

Perfect!

Post by outatime257 »

That's what the sysadmin at my company said... and it works beautifully!

Thanks!
Post Reply