Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jun 2005
    Thanked 0 Times in 0 Posts

    Question textbox input to replace text in php/html file

    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...

  • #2
    New to the CF scene
    Join Date
    Nov 2006
    San Francisco, CA, USA
    Thanked 0 Times in 0 Posts
    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.


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts