php notepad

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ralphi91
Forum Newbie
Posts: 1
Joined: Sat Aug 25, 2007 9:16 pm

php notepad

Post by ralphi91 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


i would like to make a notepad to save and load things from a text file stored on my webserver. I would like to have 3 buttons, "save", "load" and "refresh".

I am not good with php and i have found the following parts of code that would probably be useful in creating this.

Code: Select all

<?php
$myFile = "71637213418#$%.txt";

$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "$text;
fwrite($fh, $stringData);
$stringData = "----";
fwrite($fh, $stringData);
fclose($fh);//sending

php?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

What's your question?
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

small notepad code

Post by yacahuma »

first you need to create a web page with a textarea an the 3 buttons.

Actually the load is not really necessary since you can read it the first time your page is up.

Code: Select all

<?
$path  = '/mydatafolder/datafile.txt';
if (isset($_POST['btn_save']))
{
   $data = $_POST['mydata'];
   file_put_contents ( $path, $data);  
}else{
   $data = implode('', file($path));
}
?>
<html>
<body>
<form action='thisfile.php' method='post'>
<textarea rows="2" cols="20" id='mydata' name='mydata'><?=$data?></textarea>
<input type='submit' name='btn_save' value='Save' />
<input type='submit' name='btn_refresh' value='Refresh' />

<body>
</html>
I may not have all the syntax correct.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: small notepad code

Post by s.dot »

Some tag issues here :P
yacahuma wrote:

Code: Select all

<?
.....
Always use <?php to start your PHP code, since it can be used independently of the php.ini short tags setting.
ralphi91 wrote:

Code: Select all

...
php?>
To close a php section, just use ?>. The way you have it would probably cause some parsing errors.

As far as the original post, if your question is how to do it..

Get the contents of a text file

Code: Select all

$textFile = file_get_contents('txtfile.txt');
Display them in a textarea

Code: Select all

echo '<textarea rows="5" cols="30">' . $textFile . '</textarea>';
To change the contents,
Submit the form, then use file_put_contents() (php5+ i believe) or fopen() the file, fwrite() the file, fclose() the file.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
kaszu
Forum Regular
Posts: 749
Joined: Wed Jul 19, 2006 7:29 am

Post by kaszu »

Don't forget to escape data

Code: Select all

$textFile = file_get_contents('txtfile.txt');
$textFile = htmlentities($textFile);
echo '<textarea rows="5" cols="30">' . $textFile . '</textarea>';
Post Reply