I'm new to PHP and to this forum so any help with that in mind is appreciated.
Problem: I am writing a simple text editor using the fopen, fwrite, fclose and get_contents commands.
I have succeeded in getting the window to come up and drop in the existing text to edit but it is not saving. I am wondering if it has something to do with the mode I am using for fopen. I tried a couple other modes like 'a', 'a+' and 'r+' but am not having any luck. Here is my code:
//this is the get contents file
<?php
$filename = "../basictext.php";
$contents = file_get_contents($filename);?>
<form method="post" action="process.php">
<textarea cols="75" rows="30" name="content">
<?php echo $contents;?>
</textarea><br>
<input type="submit" name="Save" value="SAVE"></p>
</body>
//this is the processor
<?php
$contents = $_POST['contents'];
$filename = "../basictext.php";
$fp = fopen($filename, 'w');
fwrite($fp, $contents);
fclose($fp);
?>
Text editor code help
Moderator: General Moderators
-
nowaydown1
- Forum Contributor
- Posts: 169
- Joined: Sun Apr 27, 2008 1:22 am
Re: Text editor code help
The element on your form name is called 'content', but your processing file references 'contents'.
Re: Text editor code help
Thanks.
It's always something simple.
It's always something simple.
-
nowaydown1
- Forum Contributor
- Posts: 169
- Joined: Sun Apr 27, 2008 1:22 am
Re: Text editor code help
Always helps to have another set of eyes. Welcome to the forum!
Re: Text editor code help
Thanks. Looking forward to learning more.
This editor is really stripped down. It basically edits the code.
Where would I start if I want to make an editor that edits the text and have to edit the code? Kind of like this reply window with the B, i, etc.
This editor is really stripped down. It basically edits the code.
Where would I start if I want to make an editor that edits the text and have to edit the code? Kind of like this reply window with the B, i, etc.
Re: Text editor code help
another issue.
If I refresh the get_contents page it adds a bunch of slashes //// to the code and sometimes in the text.
seems to be where there are spaces
any reason why?
If I refresh the get_contents page it adds a bunch of slashes //// to the code and sometimes in the text.
seems to be where there are spaces
any reason why?
-
nowaydown1
- Forum Contributor
- Posts: 169
- Joined: Sun Apr 27, 2008 1:22 am
Re: Text editor code help
For the bold, italics stuff, you would want to look at using javascript that will dynamically insert/modify stuff in your textbox. As for slashes being added, I would guess its because magic_quotes_gpc is probably enabled in your php.ini. For information on how to turn it off, see:
http://us2.php.net/manual/en/security.m ... abling.php
http://us2.php.net/manual/en/security.m ... abling.php