qaq0 Posted February 3, 2007 Share Posted February 3, 2007 I was wondering how you could write a text file from a text area. The text area must display the text that was written before and have a submit button. Link to comment https://forums.phpfreaks.com/topic/36935-writting-text-area-to-a-txt-file/ Share on other sites More sharing options...
Rottingham Posted February 3, 2007 Share Posted February 3, 2007 In simplest terms as your question was... <form name="test" action="test.php" method="post"> <input type="textarea" name="test_text">Some Fun with Words!</textarea> <input type="submit" name="submit" value="Submit"> </form> test.php <? // Test for form submittal if(isset($_REQUEST["submit"])) { $text = $_REQUEST["test_text"]; $file_h = fopen("yourfilepath/text.txt", "w"); fwrite($file_h, $text, strlen($text)); fclose(); // All Done! Thank your user for their gracious input. } ?> Link to comment https://forums.phpfreaks.com/topic/36935-writting-text-area-to-a-txt-file/#findComment-176228 Share on other sites More sharing options...
qaq0 Posted February 3, 2007 Author Share Posted February 3, 2007 Thanks Link to comment https://forums.phpfreaks.com/topic/36935-writting-text-area-to-a-txt-file/#findComment-176230 Share on other sites More sharing options...
DeathStar Posted February 3, 2007 Share Posted February 3, 2007 i wondered if this code example can be edited to input data to a spicific place in txt file ex. mysql_connect ("first_textarea") and so on.. or maybe just mak it already in the file(php one) ?? Link to comment https://forums.phpfreaks.com/topic/36935-writting-text-area-to-a-txt-file/#findComment-176296 Share on other sites More sharing options...
Rottingham Posted February 3, 2007 Share Posted February 3, 2007 Deathstar, I didn't really understand the question you are asking. If you mean you have multiple chunks of text, and you want to insert them into the file, that is possible. If you knew the specific place in the text file you wanted to insert, you would change the files beginning pointer using fseek(). For instance, if the file was 2000 bytes large, and you wanted to insert your text at the middle of the file, you would do this: // Move file pointer to middle of the file fseek($file_h, 1000); // Write in the data fwrite($file_h, $test, strlen($text)); // Close file fclose($file_h); Link to comment https://forums.phpfreaks.com/topic/36935-writting-text-area-to-a-txt-file/#findComment-176331 Share on other sites More sharing options...
taps Posted February 3, 2007 Share Posted February 3, 2007 Create a file in your directory called test.txt inside write what you want. Create a file called edit2area.php or how you want call it. <?php $file = "test.txt"; // insert your filename or url here if (!isset($_POST['submit'])) { $fo = fopen($file, "r"); $fr = fread($fo, filesize($file)); echo "<form method='post' action='{$_SERVER['PHP_SELF']}'> <textarea name='newfile' rows='10' cols='50'>{$fr}</textarea> <p> <input type='submit' name='submit' value='Save' /> </form>"; fclose($fo); } else { $fo = fopen($file, "w"); $fw = fwrite($fo, $_POST['newfile']); fclose($fo); } ?> Link to comment https://forums.phpfreaks.com/topic/36935-writting-text-area-to-a-txt-file/#findComment-176392 Share on other sites More sharing options...
DeathStar Posted February 13, 2007 Share Posted February 13, 2007 I wondered because i wanted to make an installer kind of thing? and then it would just input spicific things. localhost db_name and so on.. on spicific place in the text file . Link to comment https://forums.phpfreaks.com/topic/36935-writting-text-area-to-a-txt-file/#findComment-183575 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.