View Full Version : Replace certain parts of page based on form input

06-07-2005, 02:39 AM
Hi everyone! I'm back, asking for more help (I know that's what these forms are all about, but sometimes I feel bad asking anyway)...

So far, I have this code (with much of your help already):

define('ROOT_DIRECTORY', '/var/www/html/mtd');

$searchThis = ROOT_DIRECTORY.$pageSelected;
if(is_file($searchThis)) {
$searchThis = file_get_contents($searchThis);
function findEditable() {
global $searchThis;
// Split Comments:
$split = preg_split('/(<!-- OPEN .*? CLOSE -->)/i', $searchThis, -1, PREG_SPLIT_DELIM_CAPTURE);
for($i=0; $i < count($split); $i++) {
if(substr($split[$i], 0, 9) == '<!-- OPEN') {
$subSplit[] = preg_split('/<!-- OPEN id=\"(.*?)\" type=\"(.*?)\" -->(.*?)<!-- CLOSE -->/i', $split[$i], -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
for($i=0; $i < count($subSplit); $i++) {
$returnCode[$i]['id'] = $subSplit[$i][0];
$returnCode[$i]['type'] = $subSplit[$i][1];
$returnCode[$i]['code'] = $subSplit[$i][2];
// goes on to write a form, allowing the user to edit each instance of $returnCode['code']
}This code searches $searchThis for all instances of
<!-- OPEN id="any-id-here" type="specify-type-here" -->This is the content<!-- CLOSE --> and for each occurance, makes the content between the comments editable in a form. (Note that each instance will have its own id courtesy of $returnCode[$i]['id'] = $subSplit[$i][0];)

What I need to do now is save the changes of the form back to the file $searchThis, overwriting the old content between comments with the new content. The kicker is, I have to preserve any text that is *not* between comments. As I have explained in previous posts, I am not very good with RegEx (even though I'm getting a bit better), so I am somewhat lost in this process. All I know is that I'll likely have to use fopen(); and fwrite(); at some point...

I will provide all my code upon request, but I didn't want to overpost with potentially useless info unless I was sure it would be helpful. I know this may be alot to ask help for, so: Thanks for any help in advance!!!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum