View Full Version : textbox input to replace text in php/html file

11-13-2006, 10:08 AM
Well, im trying to make it easy for me to edit a certain part of my site (like one line of text) by just have a text box input and submitting it to replace the text that already exist:

Let me explain better:

I have the text "Hello, page of doom" somewhere on my page.
I access another page on my server with a text form for input and submission.
I submit the text "Doom on all pages" into the text submission.
The text "Hello, page of doom" is replaced with "Doom on all pages"

I think there is a way by having my text be in a seperate file and use include function to put it on the page, but i dont know how to go about replacing the text in the seperate file with text input...

IS tere a script that could help me, or a link, or something...? Please Help...

11-13-2006, 10:38 AM
you could use

$file_name = 'test.txt';
$text = trim($_POST['text']);

$fp = fwrite($file_name, 'w');
if (fwrite($fp, $text) === FALSE) {
echo "Cannot write to file ($file_name)";

and then just include the file wherever it is needed

this will automatically erase anything in $file_name and replace it with whatever you post from the form. I would recommend instead writing this information to a database instead of a file this will leave room for you to customize your page a lot more in the future without having to open a file for each customization.