Page 1 of 1

Text editor code help

Posted: Wed Jun 11, 2008 12:53 pm
by clay210
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);
?>

Re: Text editor code help

Posted: Wed Jun 11, 2008 12:57 pm
by nowaydown1
The element on your form name is called 'content', but your processing file references 'contents'.

Re: Text editor code help

Posted: Wed Jun 11, 2008 1:22 pm
by clay210
Thanks.

It's always something simple.

Re: Text editor code help

Posted: Wed Jun 11, 2008 1:24 pm
by nowaydown1
Always helps to have another set of eyes. Welcome to the forum!

Re: Text editor code help

Posted: Wed Jun 11, 2008 1:38 pm
by clay210
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.

Re: Text editor code help

Posted: Wed Jun 11, 2008 1:46 pm
by clay210
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?

Re: Text editor code help

Posted: Wed Jun 11, 2008 2:22 pm
by nowaydown1
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