Web Hosting Talk







View Full Version : PHP File Editing


superdooper
07-05-2008, 06:31 AM
HI all, i know how to read a file for editing in PHP, however, i want to display different sections of the file in different text areas on the page. for example

text between;
////HEADER START
asdjkasd
////HEADER END

is in one textarea

and

////CONTENT START
dfjsdkfj
////CONTENT END

is shown in a different textarea

Thanks!!!

greg2007
07-05-2008, 09:41 AM
It depends on the file you are reading from, what contents it has etc.

If the file isn't too complex, perhaps you could just make the editor re-write the whole file contents.
Obiously you would have to take the files contents into an array to later change the relavant values in the array you changed with the editor and then output the contents of the array back to the file


I.E.
If say in the file is the bits you want to edit with textarea etc, edit those with the file editing code you are making, then in the script that adds the newly edited textarea stuff, also add the other stuff that is requird in the file.

Example:
So you could use variables in the file.
I.E.
$title = "<title>This is my title</title>";
Then echo the $title var where it's needed (I.E. in the page head/title area)

Then to edit the file to change the $title var.
$newtitle = "this is my NEW title";
$title = "<title>".$newtitle."</title>";

So you would update the array of the files contents and add the NEW $title to the OLD title in the array, thus chamnging it, then write the whole array contents back to the file again.

Obviously you would need to work carefully with <br> and \n. As the array you get from the file contents, would have a new key and value for each line in the file.

To be honests, these are just basic ideas, as it's very hard to say without knowing exactly what the file you are editing does and what's in it.

Perhaps if you post the entire requirements of this file you want to edit someone can give a more exact solution to your needs.

EDIT or perhpas using a DB table with the files contents would be easier?
in the file it would read the DB and echo out values from the DB, then in the editor it would be the db table values you would change so the file would output the new data as required.

superdooper
07-05-2008, 10:26 AM
THanks for the reply, the file is pretty basic;


<?php
///PAGE TITLE HERE
$title = "Page Title";
///END PAGE TITLE


///PAGE CONTENTS HERE
$content = <<<CONTENT

some normal html content is stuffed in here!

CONTENT;
///END PAGE CONTENTS

require 'template.php';
?>


Normally i would use a database for this and i would have it done by now but that isnt an option on this one!

Thanks

superdooper
07-05-2008, 10:34 AM
Doh, its blindly staring me in the face. Ive made this more complecatied than i need too.

Thanks for the reply and sorry for being a dumbass!:D

greg2007
07-05-2008, 11:02 AM
No problem.
Glad to be no help :D