Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6540033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:55:48+00:00 2026-05-25T10:55:48+00:00

I have written a PHP script which allows me to modify and update a

  • 0

I have written a PHP script which allows me to modify and update a file on a webpage, which works, but the script right now presents the entire contents of the file in a text area. I would like to extract just the string from the file and pre-populate it in a form text field (instead of a text area).

Below are the two files I need to update. I would like to just update the IP addresses. So the form would ideally show that mail.helloworld.com current maps to “208.164.222.2” and populate that IP address in a form text field. Same idea for the /etc/postfix/main.cf file as shown below.

/etc/hosts

IPAddress Hostname Alias
127.0.0.1 localhost deep.openna.com
208.164.222.2 mail.helloworld.com mail
208.164.222.3 web.helloworld.com web

/etc/postfix/main.cf

relayhost= 192.168.1.10

===

Current working script using textarea:

<form action="<?php echo $PHP_SELF;?>" method="post">
<textarea rows="13" cols="110" name="content">
<?
$fn = "/etc/postfix/main.cf";
print htmlspecialchars(implode("",file($fn)));

?> 
</textarea></br>
<input id= "relayhost_button" type="submit" value="Update"> 
</form> 



<?
$fn = "/etc/postfix/main.cf";
$content = stripslashes($_POST['content']);
$fp = fopen($fn,"w") or die ("Error opening file in write mode!");
fputs($fp,$content);
fclose($fp) or die ("Error closing file!");
echo "<meta http-equiv=\"refresh\" content=\"0; url=done.php\" />\n";
?>

Here is the current textarea based form:

enter image description here

New text field based form I want:

enter image description here
As always, thanks folks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T10:55:49+00:00Added an answer on May 25, 2026 at 10:55 am

    Parse the file, then present the wanted line to the user. Once (s)he has edited it, reparse the file, and replace the information. (Instead of parsing, you could just track which line number it was.)

    Other than that, the question gets a bit in depth. Do you have any specific problems?

    Also, a few non-related suggestions:

    • Replace the implode(file()) with file_get_contents.
    • Use complete opening tags (‘< ?php’ without the space)
    • Use fwrite instead of fputs (no actual justification for this one, I just avoid using aliases)
    • A large part personal preference, but I find it cleaner to do redirects with headers than with meta tags.

    Eg:

    header("Location: http://blah/done.php");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a PHP script which generates an SQL file containing all tables
I have a PHP script which works fine in PHP 5, but not in
In one app, I have an administrative backend written in PHP, which allows to
Starting out with php, I have written a basic authentication script which prints out
I have a php script written which calls an external command using exec which
I have written a script image.php that is quite long, but I've just copied
I have written a web app in PHP which makes use of Ajax requests
I have written jQuery code, in files Main.html and ajax.php . The ajax.php file
I have some code I've written in PHP for consuming our simple webservice, which
I have written a PHP script that checks whether a domain is available for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.