update html page with PHP
Posted: Tue Jun 29, 2004 1:24 am
Hello, I am writing a simple script that will update the text on a website.
My script has to parts.
a. It will find the section(s) in the html file that needs to be updated by reading the file into a string and finding certain tags (e.g. <!--startedit001--> <!--endedit001-->). Once the editable text is captured in a variable, it is displayed in the 'value' section of an html text field.
b. In the second part the user then will make the necessary changes to the text and submit the form.
This is where I'm stuck. I want to use a template file and I want to add the modified text onto it. The ideal thing to do would be to have a variable in the template file that would get replaced by the contents of the form.
I tried putting a small php script just with the print $formresult; statement in the template file, store the template code in a variable with $changedhtmlfile = file_get_contents() and re-write the html file to be edited with the updated $changeedhtmlfile string. But it doesn't work.
I could use the same process I used in the first part. Insert two comment tags and replace the text in between, but I don't know if that's the best way to do it. I figure there's gotta be a way I can just tell the script where in the template I want to insert the text.
This is my first php script, so please Please, any help would be greatly appreciated.
Tony
My script has to parts.
a. It will find the section(s) in the html file that needs to be updated by reading the file into a string and finding certain tags (e.g. <!--startedit001--> <!--endedit001-->). Once the editable text is captured in a variable, it is displayed in the 'value' section of an html text field.
Code: Select all
<?php
$filelocation = "../index2.html";
$startedit001 = "<!--starteditsection001-->";
$endedit001 = "<!--endeditsection001-->";
###########################################
//open file and read into a string
$htmlblog = file_get_contents($filelocation);
//get position of start and end tags
$pos1 = strpos($htmlblog, $startedit001);
$pos2 = strpos($htmlblog, $endedit001);
//get selected content and store it in a variable
$contentsize = $pos2 - $pos1;
$content = substr($htmlblog, $pos1, $contentsize);
//strip html tags and print
$fcontent = strip_tags($content, '<BR><B><U><I><Ol><UL><LI><A>');
$text = trim($fcontent);
echo preg_replace('/\s+/', ' ', $text);
?>This is where I'm stuck. I want to use a template file and I want to add the modified text onto it. The ideal thing to do would be to have a variable in the template file that would get replaced by the contents of the form.
I tried putting a small php script just with the print $formresult; statement in the template file, store the template code in a variable with $changedhtmlfile = file_get_contents() and re-write the html file to be edited with the updated $changeedhtmlfile string. But it doesn't work.
I could use the same process I used in the first part. Insert two comment tags and replace the text in between, but I don't know if that's the best way to do it. I figure there's gotta be a way I can just tell the script where in the template I want to insert the text.
This is my first php script, so please Please, any help would be greatly appreciated.
Tony