0

How can i edit a text file on a server and how to receive it back in a text box.And at last how to check wether a particular word is there or not.

If you can get any of this then please let me know at kvermamanas@gmail.com

You may tell me in javascript side server language or anything else.
I will be grateful as i am only 13.

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by vibhaJ
0

I believe it is php your wanting to use if the file is stored on the server.
There is a nice function called file_get_contents() and file_put_contents(). Below is an example of how to use them.

<?php
$file='path/to/file.txt';
$data=file_get_contents($file);
echo '<textarea name="text">';
echo $data;
echo '</textarea>';
if (isset($_POST) && !empty($_POST)) {
file_put_contents($file,$_POST['text']);
}
0

For checking word is there or not:
Here is code:

<?
	$file='path/to/file.txt';
	$data=file_get_contents($file);
	$findme  = 'some word';
	
	$pos = strpos($data, $findme);
	
	// Note the use of ===.  Simply == would not work as expected
	// because the position of 'a' was the 0th (first) character.
	if ($pos === false) 
	{
	   echo "The string '$findme' was not found";
	} 
	else
	{
	   echo "The string '$findme' was found and exists at position $pos";
	}
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.